VBA closing one file

  • Thread starter Thread starter colic
  • Start date Start date
C

colic

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
 
colic,

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

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Return to Main Page 1
change code name 1
Hyperlink Code 2
Make a Better Userform 1
Hide and Seek 4
create new sheets from a header row 2
Importing Multiple Text File in Excel 4
Cut, Paste and Move to next Row 3

Back
Top