ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   pointer to sub (https://www.excelbanter.com/excel-programming/348727-pointer-sub.html)

UKNewbie

pointer to sub
 
Morning all (GMT),

Just wondering if it is possible to create a flexible pointer to call other
subs within a loop. Example code below: -

For i = 3 To counter - 1
Workbooks.Open wsTD.Cells(i, 2), _
updatelinks:=False, writerespassword:=wsTD.Cells(i, 3)
Set wb2 = ActiveWorkbook
SubWB = Replace(Left(wb2.Name, Len(wb2.Name) - 4), " ", "_", 1)
Call SubWB
wb2.Close savechanges:=True
Next i


Can use pointers within C++ but can't figure out a similar method within VBA.
Any help, as always, much appreciated.

Thanks in advance,

Mike

(Win2k sp4, Office2k sp3)

keepITcool

pointer to sub
 

in xl2000 and newer (vba6) there's CallByName
wont give you efficiently compiled code.. but flexible!
see VBA help for details.

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


UKNewbie wrote :

Morning all (GMT),

Just wondering if it is possible to create a flexible pointer to call
other subs within a loop. Example code below: -

For i = 3 To counter - 1
Workbooks.Open wsTD.Cells(i, 2), _
updatelinks:=False, writerespassword:=wsTD.Cells(i, 3)
Set wb2 = ActiveWorkbook
SubWB = Replace(Left(wb2.Name, Len(wb2.Name) - 4), " ", "_", 1)
Call SubWB
wb2.Close savechanges:=True
Next i


Can use pointers within C++ but can't figure out a similar method
within VBA. Any help, as always, much appreciated.

Thanks in advance,

Mike

(Win2k sp4, Office2k sp3)


Dave Peterson

pointer to sub
 
Maybe you can use Application.run

Application.run "'" & someworkbook.name & "'!" & somemacroname


UKNewbie wrote:

Morning all (GMT),

Just wondering if it is possible to create a flexible pointer to call other
subs within a loop. Example code below: -

For i = 3 To counter - 1
Workbooks.Open wsTD.Cells(i, 2), _
updatelinks:=False, writerespassword:=wsTD.Cells(i, 3)
Set wb2 = ActiveWorkbook
SubWB = Replace(Left(wb2.Name, Len(wb2.Name) - 4), " ", "_", 1)
Call SubWB
wb2.Close savechanges:=True
Next i

Can use pointers within C++ but can't figure out a similar method within VBA.
Any help, as always, much appreciated.

Thanks in advance,

Mike

(Win2k sp4, Office2k sp3)


--

Dave Peterson

UKNewbie

pointer to sub
 
Genius... Works perfectly.

Thanks ever so and have a fab XMAS (to the whole community..!!!)

Mike

"Dave Peterson" wrote:

Maybe you can use Application.run

Application.run "'" & someworkbook.name & "'!" & somemacroname


UKNewbie wrote:

Morning all (GMT),

Just wondering if it is possible to create a flexible pointer to call other
subs within a loop. Example code below: -

For i = 3 To counter - 1
Workbooks.Open wsTD.Cells(i, 2), _
updatelinks:=False, writerespassword:=wsTD.Cells(i, 3)
Set wb2 = ActiveWorkbook
SubWB = Replace(Left(wb2.Name, Len(wb2.Name) - 4), " ", "_", 1)
Call SubWB
wb2.Close savechanges:=True
Next i

Can use pointers within C++ but can't figure out a similar method within VBA.
Any help, as always, much appreciated.

Thanks in advance,

Mike

(Win2k sp4, Office2k sp3)


--

Dave Peterson



All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com