Assigning a macro to button

ibadk

New Member
Joined
Mar 10, 2011
Messages
11
Hey Guys,

Fairly simple question. I'm pretty sure that I just don't understand some fundamental vba assinging macro bit. I have a long code, with many sub procedures in the middle. It's split into two modules. The first module simply refers to the second module every so often. I basically want to break out the second module (the one with many subs) by assigning a button to each sub. However, when I do this I get the error "argument not optional." What could I be doing wrong? I've attached a piece of the code from the second module (this module contains about 5 other sub procedures, each of which I want a button assigned to).

Code:
Public Sub executepositionRpt(Fname As String, dateinput As String)

Dim wbPositionRpt   As Workbook
Dim resultrun       As Variant
Dim Wbmain          As Workbook

'Open the Position Report Program and unprotect the worksheet so it can be edited

Set Wbmain = ActiveWorkbook
Application.Workbooks.Open (Fname)
Set wbPositionRpt = ActiveWorkbook


'Set Report Date to date inputted
wbPositionRpt.Sheets("Main").Range("ReportDate") = dateinput

'Run Position Report Program
Application.Run "'Position Report Program.xlsb'!RunAll"

'Close without saving changes to Position Report Program
wbPositionRpt.Close False

'Save Report in Liquidity folder

Call SaveFile




End Sub

'This subroutine will take a pivot table and ensure that all appropriate fields are displayed
'For example, the pivot table produced by the total position report doesn't include several fields
'such as "Sum of Mkt Value"

Public Sub initializePivot(wbk As Workbook, pivotsheetname As String, sourceptsheetname As String)

    Dim i As Integer
    Dim lastTicket As Integer
    Dim ptSourceData As String
    
    wbk.Sheets(pivotsheetname).Select
    
    Application.DisplayAlerts = False
    With ActiveSheet.PivotTables(1).PivotFields("UserValue1")
        .Orientation = xlPageField
        .Position = 1
    End With

    With ActiveSheet.PivotTables(1).PivotFields("UserValue2")
        .Orientation = xlPageField
        .Position = 1
    End With

    With ActiveSheet.PivotTables(1).PivotFields("Book")
        .Orientation = xlPageField
        .Position = 1
    End With

    With ActiveSheet.PivotTables(1).PivotFields("Type")
        .Orientation = xlPageField
        .Position = 1
    End With

    With ActiveSheet.PivotTables(1).PivotFields("Start")
        .Orientation = xlColumnField
        .Position = 1
    End With

    With ActiveSheet.PivotTables(1).PivotFields("End")
        .Orientation = xlColumnField
        .Position = 2
    End With
    
    With ActiveSheet.PivotTables(1).PivotFields("Market")
        .Orientation = xlRowField
        .Position = 1
    End With
    
    With ActiveSheet.PivotTables(1).PivotFields("Comp")
        .Orientation = xlRowField
        .Position = 2
    End With
    
    With ActiveSheet.PivotTables(1).PivotFields("Interbook")
        .Orientation = xlRowField
        .Position = 3
    End With
    ActiveSheet.PivotTables(1).AddDataField ActiveSheet.PivotTables( _
        1).PivotFields("Mkt Value"), "Sum of Mkt Value", xlSum
    ActiveSheet.PivotTables(1).AddDataField ActiveSheet.PivotTables( _
        1).PivotFields("MtM"), "Sum of MtM", xlSum
        Application.DisplayAlerts = True
        
        
    lastTicket = wbk.Sheets(sourceptsheetname).Cells(Rows.Count, "D").End(xlUp).Row
    ptSourceData = sourceptsheetname & "!R1C1:R" & lastTicket & "C16"

    wbk.Sheets(pivotsheetname).Select
    ActiveSheet.PivotTables(1).SourceData = ptSourceData
    ActiveSheet.PivotTables(1).RefreshTable
    
    
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You cannot assign a button to a subroutine that takes arguments (Fname, dateinput),
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top