Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA closing one file

Hiya I am using a macro to create a workbook in another file. I run it
from one file and then it opens up the other file. But then I want it
to save and close the file im creating the new table in.

I am struggling with what I need to do for this.

I can make it close both files but I want to keep the original file
open and save and close the 2nd file.

Any ideas :)

Sub new_workbook()
Dim ws As Worksheet
Dim newSheetName As String
newSheetName = Sheets(1).Range("D3")
Workbooks.Open FileName:= _
"\\dir\\Test\All Advisors.xls"
For Each ws In Worksheets
If ws.Name = newSheetName Or newSheetName = "" Or
IsNumeric(newSheetName) Then
MsgBox "Sheet already exists or name is invalid",
vbInformation
Exit Sub
End If
Next
Sheets.Add Type:="Worksheet"
With ActiveSheet
..Move after:=Worksheets(Worksheets.Count)
..Name = newSheetName
End With
Workbooks.Close
End Sub



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default VBA closing one file

try
activeworkbook.close

"colic" wrote in message
...
Hiya I am using a macro to create a workbook in another file. I run it
from one file and then it opens up the other file. But then I want it
to save and close the file im creating the new table in.

I am struggling with what I need to do for this.

I can make it close both files but I want to keep the original file
open and save and close the 2nd file.

Any ideas :)

Sub new_workbook()
Dim ws As Worksheet
Dim newSheetName As String
newSheetName = Sheets(1).Range("D3")
Workbooks.Open FileName:= _
"\\dir\\Test\All Advisors.xls"
For Each ws In Worksheets
If ws.Name = newSheetName Or newSheetName = "" Or
IsNumeric(newSheetName) Then
MsgBox "Sheet already exists or name is invalid",
vbInformation
Exit Sub
End If
Next
Sheets.Add Type:="Worksheet"
With ActiveSheet
Move after:=Worksheets(Worksheets.Count)
Name = newSheetName
End With
Workbooks.Close
End Sub



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default VBA closing one file

colic,

Activeworkbook.Close
wil close whatever workbook is active at the time.

John

colic wrote:

Hiya I am using a macro to create a workbook in another file. I run it
from one file and then it opens up the other file. But then I want it
to save and close the file im creating the new table in.

I am struggling with what I need to do for this.

I can make it close both files but I want to keep the original file
open and save and close the 2nd file.

Any ideas :)

Sub new_workbook()
Dim ws As Worksheet
Dim newSheetName As String
newSheetName = Sheets(1).Range("D3")
Workbooks.Open FileName:= _
"\\dir\\Test\All Advisors.xls"
For Each ws In Worksheets
If ws.Name = newSheetName Or newSheetName = "" Or
IsNumeric(newSheetName) Then
MsgBox "Sheet already exists or name is invalid",
vbInformation
Exit Sub
End If
Next
Sheets.Add Type:="Worksheet"
With ActiveSheet
Move after:=Worksheets(Worksheets.Count)
Name = newSheetName
End With
Workbooks.Close
End Sub

------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing file with macro dwake Excel Discussion (Misc queries) 3 December 2nd 09 05:49 PM
How to skip the save file notoification on file closing? Dan Excel Worksheet Functions 1 August 19th 07 02:26 PM
closing 1 file at a time Keith G Hicks Excel Discussion (Misc queries) 4 September 4th 05 02:16 AM
HTML Help not closing the file pod Excel Discussion (Misc queries) 0 April 18th 05 04:45 PM
closing current file only Adam[_8_] Excel Programming 0 August 27th 03 02:47 PM


All times are GMT +1. The time now is 06:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"