You can use below code,
You can use below code with minimal changes to your code. you can use in both ways.
Hi, Yogesh you can use below code.
Code:
Dim fso, FolderPath, objExcel, strPathExcel
FolderPath = "C:\Users\Desktop\"
strPathExcel = FolderPath&"abcd.xls"
' Get instance of FileSystemObject.
Set fso = CreateObject("Scripting.FileSystemObject")
Set objExcel = GetObject("C:\Users\Desktop\xyz.xls","")''you should provide the path of the already opened sheet. Else if you want to work with your code you need to create an object of the work sheet and then use.
If not(fso.FolderExists(FolderPath)) then
fso.CreateFolder (FolderPath)
' Create a new folder with the FileSystemObject object.
End if
objExcel.saveas strPathExcel
objExcel.Close
objExcel.Quit
You can use below code with minimal changes to your code. you can use in both ways.
Code:
Dim fso, FolderPath, objExcel, strPathExcel
FolderPath = "C:\Users\Desktop\"
strPathExcel = FolderPath&"abcd.xls"
' Get instance of FileSystemObject.
Set fso = CreateObject("Scripting.FileSystemObject")
Set objExcel = GetObject("","Excel.Application")
Set objWorkBook = objExcel.Workbooks.Open ("C:\Users\Desktop\xyz.xls")''Already opened excel path
If not(fso.FolderExists(FolderPath)) then
fso.CreateFolder (FolderPath)
' Create a new folder with the FileSystemObject object.
End if
objExcel.ActiveWorkbook.saveas strPathExcel
objExcel.ActiveWorkbook.Close
objExcel.quit
Hi, Yogesh you can use below code.
Code:
Dim fso, FolderPath, objExcel, strPathExcel
FolderPath = "C:\Users\Desktop\"
strPathExcel = FolderPath&"abcd.xls"
' Get instance of FileSystemObject.
Set fso = CreateObject("Scripting.FileSystemObject")
Set objExcel = GetObject("","Excel.Application")
Set objWorkBook = objExcel.Workbooks.Open ("C:\Users\Desktop\xyz.xls")''already opened file
If not(fso.FolderExists(FolderPath)) then
fso.CreateFolder (FolderPath)
' Create a new folder with the FileSystemObject object.
End if
objExcel.ActiveWorkbook.saveas strPathExcel
objExcel.ActiveWorkbook.Close
objExcel.quit