Fordraiders
asked on
2 workbooks but vba routine to keep current workbook open but close saveas copy
I have a vba routine that is not working properly.
I have a current workbook: I need to keep open
I have a second workbook i'm opening...getting additional string for saveas and then I just need to close the saveas workbook.
Current workbook "MyExcel1.xlsx"
In the code below i'm opening another workbook , doing a SaveAs and Then closing it.
but keeping my current workbook open.
THIS CODE IS CLOSING MY CURRENT WORKBOOK ALSO ?
Thanks
fordraiders
I have a current workbook: I need to keep open
I have a second workbook i'm opening...getting additional string for saveas and then I just need to close the saveas workbook.
Current workbook "MyExcel1.xlsx"
In the code below i'm opening another workbook , doing a SaveAs and Then closing it.
but keeping my current workbook open.
THIS CODE IS CLOSING MY CURRENT WORKBOOK ALSO ?
Public Sub CmeSaveAs()
Dim oldwkbk As String
Dim excelwrk As Excel.Application
Dim newdate As String
Dim sInput As String
Set excelwrk = Excel.Application
excelwrk.Workbooks.Open "C:\Program Files\Cme\Template_DoNot_Open\Export_Cme_Template.xlsx"
excelwrk.Visible = False
sInput = InputBox("Enter File name here")
' saveas and then close please
excelwrk.ActiveWorkbook.SaveAs "C:\Program Files\Cme\Cme_Export\" & sInput & "_" & newdate
excelwrk.ActiveWorkbook.Close
End Sub
Thanks
fordraiders
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
kimcomputer,
error on this line ?
Set newbook = excelwrk.Workbooks.Open "C:\Program Files\Cme\Template_DoNot_O pen\Export _Cme_Templ ate.xlsx"
error on this line ?
Set newbook = excelwrk.Workbooks.Open "C:\Program Files\Cme\Template_DoNot_O
ASKER
professorjim,
Current workbook. is still closing..
Current workbook. is still closing..
Set newbook = excelwrk.Workbooks.Open("C :\Program Files\Cme\Template_DoNot_O pen\Export _Cme_Templ ate.xlsx")
ASKER
ok,
profesor jim,
I commented out
' excelwrk.Visible = False
'added
excelwrk.ActiveWorkbook.Cl ose "C:\Program Files\Cme\Cme_Export\" & sInput & "_" & newdate
now it works.?
profesor jim,
I commented out
' excelwrk.Visible = False
'added
excelwrk.ActiveWorkbook.Cl
now it works.?
ASKER
Thanks to both !
Thanks for the points. Though a bit sad you didn't apply the code, as not only do you make less mistakes (using clearly defined workbooks as opposed to activeworkbook), it's also easier to read the code much later when you forgot about it (or someone else reads it).
ASKER