Excel 2010 - Verify the file is from a trusted source

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,291
Office Version
  1. 365
Platform
  1. Windows
I have a code that saves a copy of a workbook.

Code:
If globalchange = False Then Else
    ActiveSheet.Copy
    Application.DisplayAlerts = False
    invnum = Replace$(invnum, Mid$("/", 1, 1), "-")
    invnum = Replace$(invnum, Mid$("""", 1, 1), "")
    ActiveWorkbook.SaveAs FileName:="\\ih-serv\company\Shipping\Invoices\Excel\" & invnum & ".xls"
    Application.DisplayAlerts = True
    ActiveWorkbook.Close

End If


As part of a seperate routine this file is checked to see if it exists and if it does to reopen it.

Code:
invnum = Sheets("input").Range("A1").Value
invnum = Replace$(invnum, Mid$("/", 1, 1), "-")
invnum = Replace$(invnum, Mid$("""", 1, 1), "")

If Fileexists("\\ih-serv\company\Shipping\Invoices\Excel\" & invnum & ".xls") = True Then
    runnew = MsgBox("This invoice has already been generated" & vbCrLf & "Do you want to generate a new copy?", vbYesNo, "Warning")
    If runnew = 7 Then
        globalchange = False
        Application.DisplayAlerts = False

        Application.Workbooks.Open ("\\ih-serv\company\Shipping\Invoices\Excel\" & invnum & "*")
        Application.DisplayAlerts = True
        
        Workbooks(invnum).Sheets("invoice EDIT").Range("A1:W402").Copy Destination:=Workbooks("invoice").Sheets("invoice EDIT").Range("A1").Paste
        Workbooks(invnum).Close
    Else
    newinvoice
    End If
Else
    newinvoice
End If


However if I get an error stating that the file is not in recognisable format and do I want to open it?

How do I save it so it doesn't give this error?


I have added the Application.DisplayAlerts = False and the file is opened but then "Workbooks(invnum)" doesn't work - Subscript out of range
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You've told it to save with a file extension of XLS but you didn't tell it to write the file in 97-2003 format. Try this:-
Code:
ActiveWorkbook.SaveAs FileName:="\\ih-serv\company\Shipping\Invoices\Excel\" & invnum & ".xls"[COLOR=red][B], FileFormat:=xlExcel8    [/B][/COLOR]
 
Upvote 0
my code has to be universal from 2000 to 2010.

If I save as xlsx it will cause problems from older versions
 
Upvote 0
Sorry was replying to the previous poster.

Thanks for the answer
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,507
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top