1

I created a custom UI in excel 2007 as a part of xlam add-in. The custom tab includes a button that opens a website when clicked.

I used ThisWorkbook.followHyperlink "address"

The add-in is password protected which causes excel to crash whenever i click on the button while in xlam add-in. Everything works fine when I use it in an .xlsm file.

I think the problem is in the ThisWorkbook being password protected. I could use ActiveWorkbook instead but the app would crash when there is no workbook open.

Any suggestions how I could work around this? (Unprotecting the file is not an option)

Mr1159pm
  • 774
  • 1
  • 10
  • 21
  • Do you have any error handling code around?? That would help if you switch from `ThisWorkbook` into `ActiveWorkbook` according to what you said. You could show part of your code to get additional information... – Kazimierz Jawor Apr 09 '13 at 05:31
  • That's all the code there is in the UI call back function. It is just meant to go to a website when button is clicked. Excel just crashes I don't have any error code or anything. – Mr1159pm Apr 09 '13 at 05:44

1 Answers1

1

Including information from comment + assumption that this need to work only when any activeworkbook is open... than you could try to change from Thisworkbook into Activeworkbook in the way like this:

Sub FollowingHyperlink()

   'check if there is anything open
If Not ActiveWorkbook Is Nothing Then
    ActiveWorkbook.FollowHyperlink "http://www.stackoverflow.com"
Else
    'if not... it depends what you have and what you need
    'you could just open any new workbook
    '**This part of code edited**
    'or use this technique to navigate to page using IE:
    Dim ieAPP
    Set ieAPP = CreateObject("InternetExplorer.application")
    ieAPP.Visible = True
    ieAPP.navigate "http://www.stackoverflow.com"
End If

End Sub
Anonymous Type
  • 3,051
  • 2
  • 27
  • 45
Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
  • I decided to open a new workbook in the else section but I am not really satisfied with that solution. Is there a way to open webpage that does not require a workbook object? Do you know why it requires workbook object at all? – Mr1159pm Apr 10 '13 at 01:27