返回列表 上一主題 發帖

二個巨集程式問題

二個巨集程式問題

1.請問我的巨集程式中有很多個CommandButton (1   2    3),每個CommandButton下面都有個別巨集程式
現在我要做一個CommandButton4 執行後可以依序執行CommandButton1→CommandButton2→CommandButton3巨集程式?
(在不使用到模組的情況下)
2.如何設計巨集程式來自動啟動excel 樞紐分析表中"更新資料"的功能
以上請各位先進協助~~謝謝

回復 1# lone_tiger0303
  1. Private Sub CommandButton4_Click()
  2.     CommandButton1_Click
  3.     CommandButton2_Click
  4.     CommandButton3_Click
  5. End Sub
  6. '***************
  7. Private Sub Workbook_Open()
  8.     '可 2 選 1
  9.     'Me.RefreshAll                  '更新指定活頁簿中所有外部資料範圍和樞紐分析表報表。
  10.     'Sheet1.QueryTables(1).Refresh  '可更新指的工作表(Sheet1)中的第1個查詢表
  11. End Sub
複製代碼

TOP

我也和樓主出現同一樣的問題.
我還一直用 : Call CommandButton1_Click
Y-Y " 怪不得沒實現不了.

學習了.謝謝~
NeverTry , NeverNo !

TOP

回復 3# StanleyVic

Call  陳述示 VBA說明
當您要呼叫一個程序時,並不一定要使用 Call 關鍵字。但如果您使用Call 關鍵字來呼叫一個需要引數的程序,那麼 argumentlist 也必須要加上括號。如果省略了 Call 關鍵字,那麼也必須要省略括號。如果您使用 Call 語法來呼叫內建函數或使用者定義函數,則函數的傳回值將會無法傳回。

Y-Y " 怪不得沒實現不了
可能是你呼叫不是同模組的程序, 且如呼叫的是物件模組,前面要指明物件的名稱如  Call  Sheet1.Ex  或  Sheet1.Ex

TOP

本帖最後由 StanleyVic 於 2011-7-20 10:27 編輯

請問...如果代碼是以下例如, 其中一個被引用是有屬性(DblClick)

Private Sub CommandButton1_Click()
    MsgBox ("AA")
End Sub

Private Sub CommandButton2_Click()
    MsgBox ("BB")
End Sub

Private Sub CommandButton3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    MsgBox ("CC")
End Sub

'~~~ 現在開始引用 Button1~3 ..

Private Sub CommandButton4_Click()
    CommandButton1_Click
    CommandButton2_Click

'以下兩個我都試過.都不行. 這種情況.我又要如何才實現..謝謝大大建議一下.   
    'CommandButton3_Click
    'CommandButton3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
NeverTry , NeverNo !

TOP

回復 5# StanleyVic
Sheet1: Sub CommandButton1_Click() '公用
Call Sheet1.CommandButton1_Click
Sheet1: Private Sub CommandButton1_Click() '私用
Run "Sheet1.CommandButton1_Click"
'CommandButton3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
這是 CommandButton發生在使用者將指標移至物件上,按兩下滑鼠鍵時。的事件程序

TOP

回復 6# GBKEE


    謝謝大大的說明.我開始了解和明白了.
Private Sub CommandButton3_DblClick(ByVal Cancel As MSForms.ReturnBoolean)  
' 它是屬私用的, 再加上本身我之前己經定了它的屬性為 ( DblClick ), 所以就不能被調用出來 !

又上了一課 ^,^" thx~
NeverTry , NeverNo !

TOP

1.請問我的巨集程式中有很多個CommandButton (1   2    3),每個CommandButton下面都有個別巨集程式,現在我要做一個CommandButton4 執行後可以依序執行commandButton1→CommandButton2→CommandButton3巨集程式?(在不使用到模組的情況下)
針對第一個問題是指再同一個檔案內
但如果再不同檔案時要如何設定呢

TOP

不同檔案的巨集要執行還是必須把該檔案打開
或用個人巨集活頁簿或用增益集幕後開啟。

TOP

oobird 老師
我是指已經用巨集(excel檔案B)來開啟一個excel檔案A
但要
如何用excel檔案B中的commandButton1
去執行excel檔案A中的commandButton1

TOP

        靜思自在 : 生氣,就是拿別人的過錯來懲罰自己。
返回列表 上一主題