Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to save to a new file when file already exists in VB?

Hi,

I don't have much knowlegde of VB and i'm trying to save an exported excelfile without overwriting the other.

sub export
set MyTable = ActiveDocument.GetSheetObject("CH21")
MyTable.ExportEx "C:\temp\overview_1.xls",5
end sub

that's the code behind my button so each time i press it i want to create an overview_2, overview_3, ...
pls help 🙂

1 Reply
Miguel_Angel_Baeyens

Hello,

If you always need to add a sequence number to your files, you can create a variable vFileSeqNo and using the following code

Sub export Set MyTable = ActiveDocument.GetSheetObject("CH21") Set vSN = ActiveDocument.Variables("vFileSeqNo") vSNs = vSN.GetContent.String MyTable.ExportEx "C:\temp\overview_" & vSNs & ".xls",5 vSN.SetContent vSNs +1, trueEnd Sub


Hope that helps