麻辣家族討論版版's Archiver

y54161212 發表於 2022-5-7 10:55

分頁B執行分頁A程式

想寫一個程式
利用第二頁程式 command button
來執行第一頁程式commandbutton

但都會出現 run time error "28" out of stack space
想請教各位先進是要怎麼修改?




[attach]34849[/attach]
[attach]34850[/attach]

lee88 發表於 2022-5-7 15:09

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118777&ptid=23654]1#[/url] [i]y54161212[/i] [/b][code]Private Sub CommandButton1_Click()  '<--** Sheet2 的程序**
Dim sht As Worksheet, sht2 As Worksheet
Dim i As Integer, j As Integer, k As Integer
Set sht = Worksheets("Sheet1")
Set sht2 = Worksheets("Sheet2")
Application.Goto sht.Range("A1")
'  CommandButton1_Click    <--  執行的是Sheet2 的程序
'**   CommandButton1_Click  這是Sheet2 的程序
'** 一直在 一直地再 重複執行Sheet2 的CommandButton1_Click 程序
'** 錯誤碼 28 表堆疊空間不夠用了 *****
  'Private Sub   表私用的程序要用   Run  來呼叫 執行的程序
  Run "Sheet1.CommandButton1_Click" '**執行Sheet1 的程序**
End Sub[/code]

y54161212 發表於 2022-5-7 16:06

[quote]回復  y54161212
[size=2][color=#999999]lee88 發表於 2022-5-7 15:09[/color] [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118779&ptid=23654][img]http://forum.twbts.com/images/common/back.gif[/img][/url][/size][/quote]

感謝您的即時回應
這也是我一直以來的問題

因為像其他的我也是照上述的寫法
卻又可以執行~


    [attach]34851[/attach]
[attach]34852[/attach]

y54161212 發表於 2022-5-7 16:33

[quote]感謝您的即時回應
這也是我一直以來的問題

因為像其他的我也是照上述的寫法
卻又可以執行~


  ...
[size=2][color=#999999]y54161212 發表於 2022-5-7 16:06[/color] [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118780&ptid=23654][img]http://forum.twbts.com/images/common/back.gif[/img][/url][/size][/quote]


剛剛稍微測試了一下
Run "Sheet1.commandbutton1_click"
這一個指令
即使我把sheet1的名稱改為 LSR
變成 "Run "sheet1.commandbutton1_click" 還是可以執行

意思是只要開始就確認了嗎? 或者我可以在哪查到指引?

lee88 發表於 2022-5-8 14:10

[i=s] 本帖最後由 lee88 於 2022-5-8 14:16 編輯 [/i]

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118781&ptid=23654]4#[/url] [i]y54161212[/i] [/b]
[quote]即使我把sheet1的名稱改為 LSR
變成 "Run "sheet1.commandbutton1_click" 還是可以執行[/quote]
名稱改為 LSR 應是改工作表的名稱
你不是改[color=Red][size=4]工作表物件[/size][/color]的名稱,所以還是可以執行

[attach]34854[/attach]


Public Sub CommandButton5_Click()= Sub CommandButton5_Click()
Public  公用的程序 當然可以呼叫
**********************************************
如果  公用的程序 在一般模組中
可以不加上 一般模組的名稱 直接 呼叫 公用的程序

y54161212 發表於 2022-5-13 09:09

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118782&ptid=23654]5#[/url] [i]lee88[/i] [/b]


    經過您的提醒
    仔細一看,可以呼叫的確實寫成public !
    我再好好研究看看 工作模組 跟 sheet名稱的差異
    萬分感謝!!!

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供