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).
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