leezac
asked on
Close a file vba
Using the code below to open a file. How would I close the file?
DIV = Application.GetOpenFilenam e(FileFilt er:="xls*. Files (*.xls*), *.xls*", Title:="Please select a file")
'browse boxes may be on the main parm sheet i.e. Sheets("Main").VAR_DIV = DIV
' Application.EnableEvents = False
'Application.DisplayAlerts = False
Sheets("Variances").VAR_DI V = DIV
Workbooks.Open (DIV)
DIV = Application.GetOpenFilenam
'browse boxes may be on the main parm sheet i.e. Sheets("Main").VAR_DIV = DIV
' Application.EnableEvents = False
'Application.DisplayAlerts
Sheets("Variances").VAR_DI
Workbooks.Open (DIV)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brad - this is in relation to last post you helped with
This is what I am using to close. the close line did not work until I added the Set line. Is that correct though?
__________________________ __________ __________ __________ __
Lastrow = ActiveSheet.Cells(Rows.Cou nt, 1).End(xlUp).row
Range("G4:G7" & Lastrow).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Cap Gain Div Cust Variance Template.xlsm").Activate
Range("L3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Close the workbook without displaying a warning about unsaved file. Two alternatives are shown.
Set wb = Workbooks.Open(DIV)
wb.Close SaveChanges:=False 'Close the file using a workbook
End Sub
This is what I am using to close. the close line did not work until I added the Set line. Is that correct though?
__________________________
Lastrow = ActiveSheet.Cells(Rows.Cou
Range("G4:G7" & Lastrow).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Cap Gain Div Cust Variance Template.xlsm").Activate
Range("L3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Close the workbook without displaying a warning about unsaved file. Two alternatives are shown.
Set wb = Workbooks.Open(DIV)
wb.Close SaveChanges:=False 'Close the file using a workbook
End Sub
In VBA, "Set" is required whenever assigning objects (such as workbooks and Sheets) to variables.
It's not needed for lines like this:
Application.CutCopyMode = False
because the property is not an object.
It's not needed for lines like this:
Application.CutCopyMode = False
because the property is not an object.
Open in new window