Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I'm using Macro below to export the excel file to a specific folder. However, it will overwrite if there's existing file without warning. How can I create a warning? Thanks.
'Main
sub exportToExcelMain
Dim path
path = getExportPathMain()
dim o
Set o = ActiveDocument.GetSheetObject("Main")
o.ExportBiff path
Set o = nothing
msgbox("Export to " & path & " succeeded!")
end sub
function getExportPathMain
getExportPathMain = ActiveDocument.Variables("Main Export").GetContent.String
end function
Hi. Try this
sub exportToExcelMain
Dim path
path = getExportPathMain()
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(path) Then
If MsgBox(path & " already exists. Do you want to replace it?", vbYesNo, "Confirm Save As") = vbNo Then
Exit sub
End If
End If
dim o
Set o = ActiveDocument.GetSheetObject("Main")
o.ExportBiff path
Set o = nothing
msgbox("Export to " & path & " succeeded!")
end sub
function getExportPathMain
getExportPathMain = ActiveDocument.Variables("Main Export").GetContent.String
end function
Google vbscript check if file exists
Hi. Try this
sub exportToExcelMain
Dim path
path = getExportPathMain()
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(path) Then
If MsgBox(path & " already exists. Do you want to replace it?", vbYesNo, "Confirm Save As") = vbNo Then
Exit sub
End If
End If
dim o
Set o = ActiveDocument.GetSheetObject("Main")
o.ExportBiff path
Set o = nothing
msgbox("Export to " & path & " succeeded!")
end sub
function getExportPathMain
getExportPathMain = ActiveDocument.Variables("Main Export").GetContent.String
end function
thank you soo much!!