My macro doesn't work with other people's computers?

G

Guest

I have a simple macro to show custom views that are launched by a combo box.
It works fine on my computer, but crashes sporadically on other people's
machines in the office. We work on a shared network drive. Any ideas?
Here's my code:
Private Sub Markets_Change()
Dim varView As String
View = ActiveSheet.Range("b2")
ActiveWorkbook.CustomViews(View).Show
End Sub
 
N

Norman Jones

Hi Gary,

What error message do other users encounter and,
View = ActiveSheet.Range("b2")

to

View = ActiveSheet.Range("b2").Value

or, if the ComboBox is from the Controls Toolbox,

View = Me.Range("B2")

Additionally - though I assume that it is a typo:
ActiveWorkbook.CustomViews(View).Show

should probably be
ActiveWorkbook.CustomViews( varView ).Show
 
G

Guest

Private Sub Markets_Change()
Dim varView As String
'If varView is string shouldn't view be
varView = ActiveSheet.Range("b2")
'View = ActiveSheet.Range("b2")
ActiveWorkbook.CustomViews(View).Show
End Sub
 
N

NickHK

Gary,
It would be a good idea to read about 'Option Explicit" in the Help.

Hint: varView <> View

NickHK
 
G

Guest

Thanks, but the changes didn't work. Still crashes at least every other time
it is run. Hangs up on ActiveWorkbook.CustomViews(View).Show with an error
code 5.
 
G

Guest

The use of Me.Range ("b2") didn't work either. It caused Excel to crash.
The macro is hanging up on ActiveWorkbook.CustomViews(View).Show with an
error code 5. It seems to happen every other attempt to launch the macro.

I did try using a text box with the macro assigned and the varView
suggestion and that seems to work. Don't understand why.

Thanks for your help as I am new to vba.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top