如果我以BeforeRightClick
的形式運行它,我有這個子/宏。不過,我想改變它,所以我可以實際使用右鍵並將宏放在按鈕上。
所以我試圖改變BeforeRightClick
的名字。
我已經嘗試使用正常窗體按鈕和ActiveX。
這一切+更多的代碼是根據工作表Sheet1,而不是模塊貼
在按鈕下運行子程序 -
Dim tabA As Variant, tabM As Variant
Dim adrA As String, adrM As String
' Set columns (MDS tabel) where data should be copied to (APFtabel)
'Post to
'P1-6 divisions ' Name adress, etc
Const APFtabel = "P1;P2;P3;P4;P5;P6;E9;E10;E13;E14;E23;N9;N10;N11;N12;N20"
'Load data from
Const MDStabel = "N;O;P;Q;R;S;H;Y;Z;AB;W;AF;T;D;AA;V;"
Dim APF As Workbook
' APFilNavn is the name of the AP form
Const APFilNavn = "APForm_macro_pdf - test.xlsm"
' Const APFsti As String = ActiveWorkbook.Path
Const APFarkNavn = "Disposition of new supplier"
' APsti is the path of the folder
Dim sysXls As Object, APFSti As String
Dim ræk As Integer
Private Sub CommandButton1_Click()
APFormRun
End Sub
' Here I changed it from BeforeRightClick
Private Sub APFormRun(ByVal Target As Range, Cancel As Boolean)
Dim cc As Object
If Target.Column = 8 Then
APFSti = ActiveWorkbook.Path & "\"
If Target.Address <> "" Then
For Each cc In Selection.Rows
Cancel = True
ræk = cc.Row
Set sysXls = ActiveWorkbook
åbnAPF
overførData
opretFiler
APF.Save
APF.Close
Set APF = Nothing
Set sysXls = Nothing
Next cc
End If
End If
End Sub
Private Sub overførData()
Dim ix As Integer
tabA = Split(APFtabel, ";")
tabM = Split(MDStabel, ";")
Application.ScreenUpdating = False
For ix = 0 To UBound(tabM) - 1
If Trim(tabM(ix)) <> "" Then
adrM = tabM(ix) & ræk
If tabA(ix) <> "" Then
adrA = tabA(ix)
End If
With APF.ActiveSheet
.Range(adrA).Value = sysXls.Sheets(1).Range(adrM).Value
End With
End If
Next ix
End Sub
Private Sub opretFiler()
' Here I run some other macro exporting the files to Excel and PDF
btnExcel
btnExportPDF
End Sub
嗨@cybermike謝謝:)我試着用Sheet1.APFormRun,我試圖把它全部移到一個模塊。這兩個都不工作:(如果我嘗試使用'Sheet1.APForm',我得到'方法或數據成員未找到' – Niclas 2015-04-02 13:43:18
我無法調試您的代碼,因爲其中間存在亂碼:åbnAPFoverførDataopretFiler。您的代碼不會「編譯「在我的VBA for Excel中,爲了從一個按鈕中調用一個子按鈕,最好將宏名稱放入按鈕的定義中(右鍵點擊按鈕並選擇」Assign Macro ...「。使用CommandButton1_Click()工程但是在klunky中,同樣在CommandButton1_Click()中,你試圖調用不帶參數的APFormRun,但是子需要參數,你需要清理你的代碼,並且明確地執行一些Debug-> Compile,直到所有的錯誤都被解決。 – cybermike 2015-04-02 13:53:09
我感謝你的努力,但是我不明白我應該如何清理它,它使用rightclick函數完美工作,我希望它在buttonclick上運行,如果我將整個代碼複製到模塊中,我不能在t下找到任何宏他開發人員選項卡/分配宏。我嘗試了公開,私人和沒有。我很困惑。 – Niclas 2015-04-02 14:02:35