Thread
:
Bug: Call Sub in other book
View Single Post
#
2
Posted to microsoft.public.excel.programming
Gary L Brown
external usenet poster
Posts: 219
Bug: Call Sub in other book
Assuming that what you want is for dowhat() to go back to workbook#2. To do
that, you need to let dowhat() know where it's being called from by using a
parameter containing the calling workbook's name...
Global wb as workbook
sub dowhat(strWorkbook as string) <==changed
set wb = strworkbook <==added
wb.activate
...more code
set wb = nothing <==added
end sub
Private Sub Worksheet_Change(ByVal Target As Range)
dim strMacro2Run as string <==added
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Range("B1:B20"), Target) Is Nothing Then Exit Sub
strMacro2Run = "workbook1.xls!dowhat(" & ActiveWorkbook.Name & ")" <==added
application.run strMacro2Run <==changed
End Sub
HTH,
--
Gary Brown
If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.
"jotor14" wrote:
I have this code in workbook#1
Global wb as workbook
sub dowhat()
wb.activate <<<< error here
...more code
end sub
============
and this code in a sheet of workbook#2
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Range("B1:B20"), Target) Is Nothing Then Exit Sub
application.run "workbook1.xls!dowhat"
End Sub
The problem is that dowaht works if run from a macro in workbook#1 but not
when called from workbook#2 when a cell changes. The error I get is "Object
Required" which I assume is because "wb" is empty. Can someone please let me
know what I am missing.
thanks
Reply With Quote
Gary L Brown
View Public Profile
Find all posts by Gary L Brown