Problems calling macros from "ThisWorkbook"

  • Thread starter Thread starter blesbok
  • Start date Start date
B

blesbok

I am trying to call a macro from a sheet using thisworkbook, however,
don't think it allows this. Therefore as a solution I just recopie
the macro that I was using into "thisworkbook". However, th
'Sheets("Charts").ChartObjects("Chart "
r).SeriesCollection(1).XValues = ' command does not seem to b
recognized in this object, so now I am unable to autoupdate the chart
which was the whole reason for this whole process. Any help in eithe
getting that command to work in "thisworkbook" or allowing me to call
macro from a sheet using "thisworkbook" would be greatly appreciated
 
I had difficulty understanding the question.

But if the procedure is behind a worksheet, you could use:

Option Explicit
Public Sub mySub()
MsgBox "hi from the sheet"
End Sub

And call it via:
Option Explicit
Private Sub Workbook_Open()
Call Sheet1.mySub
End Sub

If the procedure is in ThisWorkbook:
Option Explicit
Public Sub mySub()
MsgBox "hi from thisworkbook"
End Sub

and called elsewhere (from a sheet or general module):
Option Explicit
Sub other_sub()
Call ThisWorkbook.mySub
End Sub

But I think moving general procedures to General modules is the best/safest bet.
 

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

Back
Top