Compile Error to working VBA when new module added

dougiek7

New Member
Joined
Nov 29, 2016
Messages
5
Trying to incorporate two modules into an excel sheet and am running into an issue that I haven't been able to diagnose. Independently the modules work but when both are in the file it gives me a "Compile Error: Wrong number of arguments or invalid property assignment" with the Sub line highlighted in debug. I don't know enough to diagnose further and was hoping I could get some guidance here.

Module 1 - creates new file and email
Code:
    Dim fPO As String    Dim fDate As Date
    Dim fPath As String
    Dim POFile As String
    Dim Template As String
    Dim yearfolder As String
    Dim monthfolder As String
    Dim newfolderpath As String
    Dim FileName As String


Sub CreatePOFile()
'
' Creates new file for each PO
'


'
    
    
    fPO = Range("C4").Value
    fDate = Date - 3 'adjust to change date used in file name
    fPath = "\\Kforce.com\Group\TAMPA\CORP\Strategic Accounts\Strategic Accounts Operations\CLIENT REPORTS\HP\HP Weekly PO Reporting" 'adjust where file is saved
    Template = ActiveWorkbook.Name
    monthfolder = Format(fDate, "mm. mmmm YYYY")
    yearfolder = Format(fDate, "YYYY")
    newfolderpath = fPath & "\" & yearfolder & "\" & monthfolder
    FileName = fPO & " Weekly Report as of " & Format(fDate, "yyyymmdd")
  
'
'
'


    'Format pivot table header
    Rows("7:7").Select
    With Selection
        .HorizontalAlignment = xlCenter
    End With


    'Create new workbook and save individual PO file. Creates new folders if nonexistant
    Workbooks.Add
    
    If Len(Dir(fPath & "\" & yearfolder, vbDirectory)) = 0 Then
        MkDir fPath & "\" & yearfolder
    End If
    If Len(Dir(fPath & "\" & yearfolder & "\" & monthfolder, vbDirectory)) = 0 Then
        MkDir fPath & "\" & yearfolder & "\" & monthfolder
    End If
    
    ActiveWorkbook.SaveAs FileName:=newfolderpath & "\" & FileName, FileFormat:=51
    Application.DisplayAlerts = True
    
    POFile = ActiveWorkbook.Name
    
    'Copy Pivot information to new file
    Windows(Template).Activate
    Range("B7").Select
    ActiveCell.CurrentRegion.Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Range("A1").Select
    
    Windows(POFile).Activate
    Range("B7").Select
    ActiveSheet.Paste
    
    ActiveSheet.Name = fPO
    
    'Formatting PO File and adding information fields
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "Weekly PO Report"
    With Selection.Font
    .Name = "Calibri Light"
        .Size = 18
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight2
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMajor
    End With
    
    Range("B4").Value = "PO Number:"
    Range("B5").Value = "Date Range:"
    
    Range("B4:B5").Select
    With Selection
        .Interior.Pattern = xlSolid
        .Interior.PatternColorIndex = xlAutomatic
        .Interior.ThemeColor = xlThemeColorAccent2
        .Interior.TintAndShade = 0
        .Interior.PatternTintAndShade = 0
        .Font.ThemeColor = xlThemeColorDark1
        .Font.TintAndShade = 0
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    
    Range("C4").Value = fPO
    Range("C5").FormulaR1C1 = "=TEXT(MIN(C[-1]),""m/d/yyyy"")&"" - ""&TEXT(MAX(C[-1]),""m/d/yyyy"")"
    Range("C4:C5").Select
    With Selection
        .Interior.Pattern = xlSolid
        .Interior.PatternColorIndex = xlAutomatic
        .Interior.ThemeColor = xlThemeColorDark1
        .Interior.TintAndShade = -0.149998474074526
        .Interior.PatternTintAndShade = 0
        .HorizontalAlignment = xlCenter
    End With
    
    Cells.Select
    Cells.EntireColumn.AutoFit
    Columns("B:B").Select
    Selection.ColumnWidth = 15
    ActiveWindow.DisplayGridlines = False
    Range("A1").Select
    
    
    'asks if email should be created
    Dim answer As Integer
    
    answer = MsgBox("Would you like to create email?", vbYesNo + vbQuestion, "Email Option")
    
    If answer = vbYes Then EmailFile
    Else
    End If
        
End Sub
    
Sub EmailFile()
    
    'Creates email with file attached
    Dim OutApp As Object
    Dim OutMail As Object
    Dim MailBody As String


    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    MailBody = "[FONT=calibri]" & "Hello,

" & _
                "Attached you will find the weekly report for " & fPO & "." & "

" & _
                "If you have any questions or discrepancies, please let me know!

Regards," & "[/FONT]
"


    On Error Resume Next
    With OutMail
        .Display
        .to = ""
        .CC = ""
        .BCC = ""
        .Subject = FileName
        .HTMLbody = MailBody & .HTMLbody
        .Attachments.Add ActiveWorkbook.FullName
        
    End With
    On Error GoTo 0


    Set OutMail = Nothing
    Set OutApp = Nothing
    
End Sub

Module 2 - formats raw data tab for ease of use
Code:
Sub Format()'
' Removes previous raw data and deletes the blank rows so the table doesn't need to be resized upon copy paste of new data
'


    On Error Resume Next
    Rows("4:" & Rows.Count).ClearContents
    Range("raw[Last Name]").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    Range("a3:z3").ClearContents
    Range("a3").Activate
       
    
End Sub


Sub Refresh()


Dim answer As Integer


If Range("a3") = "" Then


MsgBox ("Please paste new data before clicking Refresh.")


Else
    ActiveWorkbook.RefreshAll
End If


End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Got an answer elsewhere - second module sub was called Format which was the source of the error. Lesson learned is not to name sub's as function names.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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