Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2011, 01:48 PM
Authorized User
 
Join Date: May 2011
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Default How to close and save excel file .

I am trying to delete first 10 lines from a .xlsx and b.xlsx , it is happening properly but sheets are not getting closed and saved . below is the code how to close and save the file .

Sub Test()
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

Set objWorkbook = objExcel.Workbooks.Open("D:\a.xlsx")
Set objWorksheet = objWorkbook.Worksheets("Sheet1")

Set objWorkbook = objExcel.Workbooks.Open("D:\b.xlsx")
Set objWorksheet2 = objWorkbook.Worksheets("Sheet1")

objWorksheet.Rows(17).Offset(-16).Resize(16).Delete

objWorksheet2.Rows(18).Offset(-17).Resize(17).Delete

End Sub .
 
Old November 16th, 2011, 09:45 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

You can try something like this:

Code:
Sub Test()

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1 = objExcel.Workbooks.Open("D:\a.xlsx")
Set objWorksheet1 = objWorkbook.Worksheets("Sheet1")
Set objWorkbook2 = objExcel.Workbooks.Open("D:\b.xlsx")
Set objWorksheet2 = objWorkbook.Worksheets("Sheet1")
objWorksheet.rows(17).Offset(-16).Resize(16).Delete
objWorksheet2.rows(18).Offset(-17).Resize(17).Delete
objWorkbook1.Save
objWorkbook1.Close (False)
objWorkbook2.Save
objWorkbook2.Close (False)
objExcel.Quit ' close Excel
End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
The Following User Says Thank You to Shasur For This Useful Post:
honey26 (November 17th, 2011)
 
Old November 17th, 2011, 03:47 AM
Authorized User
 
Join Date: May 2011
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thanks :) it worked ....





Similar Threads
Thread Thread Starter Forum Replies Last Post
Save a file in CSV format thru Excel VBA macro roli2712 Excel VBA 1 July 11th, 2007 03:05 AM
Save Excel file. dpkbahuguna ASP.NET 2.0 Basics 1 March 10th, 2007 07:47 PM
Excel Workbook Save: Trap Temp file creation Shasur Excel VBA 0 July 3rd, 2006 10:07 PM
XMLHttp ... save it as Excel file .. vmvadivel SQL Server DTS 0 November 30th, 2005 08:37 AM
Open & Close Excel file in the background mikezhang Classic ASP Professional 0 March 17th, 2004 08:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.