1

I'm currently working on an Excel program with VBA and I need to open a file. I have the code below, which all works fine except when a user opens a file a warning message appears stating that some files could contain viruses etc. This is fine, however if a user presses cancel so they decline the opening then VBA spits the dummy. Is there a way to avoid this? Thanks.

Public Sub openFile ()
  Dim file As String
  file = "c:\somefile"
  ActiveWorkbook.FollowHyperlink         Address:=file, NewWindow:=True
End Sub
Community
  • 1
  • 1
meowcat
  • 171
  • 1
  • 12
  • @RandomDownVoter: Down votes should be explained in a comment especially for a new user. This is a reasonably well-formed question and is on-topic. Consider reversing your down vote. – Rachel Hettinger Dec 18 '14 at 02:11

2 Answers2

0

Unforetunately not, the problem I've found when using vba for excel is that it is an extension to a pre-existing user driven program so input requests are inevitable, they've caused me far too many headaches. It could be possible to simulate a keylog to automatically hit enter and accept the warning but this solution would not be reliable and I'm not even sure possible in vba.

Sam Weston
  • 128
  • 1
  • 12
0

By design, security is managed on the user's computer and is not to be overruled by a macro.

Have your users add the location of the file to their trusted locations so the file can be opened without being checked by the Trust Center (Excel Options -> Trust Center -> Trust Center Settings -> Add new location).

Rachel Hettinger
  • 7,927
  • 2
  • 21
  • 31