Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
If you are a Qlik Insight Bot user, join this collaborative group: JOIN GROUP
Highlighted
New Contributor

Macro Export to Excel will Overwrite Data without Warning.

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

1 Solution

Accepted Solutions
Highlighted
Valued Contributor

Re: Macro Export to Excel will Overwrite Data without Warning.

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

View solution in original post

3 Replies
Highlighted
Honored Contributor II

Re: Macro Export to Excel will Overwrite Data without Warning.

Google vbscript check if file exists

Highlighted
Valued Contributor

Re: Macro Export to Excel will Overwrite Data without Warning.

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

View solution in original post

Highlighted
New Contributor

Re: Macro Export to Excel will Overwrite Data without Warning.

‌thank you soo much!!