Solved

Compile Error on Macro

Posted on 2014-01-03
4
271 Views
Last Modified: 2014-01-03
Hi Guys, I have been running this macro for months but for some reason I am getting  "Compile error - Wrong Number of arguments or invalid property assignment" on the word "Format". Anyone any ideas why? Below is code:

Dim target As Range, target1 As Range, target2 As Range, target3 As Range, target4 As Range, target5 As Range, target6 As Range, target7 As Range, target8 As Range, target9 As Range, target10 As Range, target11 As Range
Dim Prevday As String

Prevday = WorksheetFunction.WorkDay(Date, -1)

Prevday = Format(Prevday, "DDMMYY")
'


    Workbooks.OpenText Filename:= _
        "V:\Treasury Finance Controls\Ledger v SS Recs\EOD Recs\BS\StructNotesBSRec_Daily_" & "*.txt" _
        , Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
        Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
        Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
        Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
        , 1), Array(16, 1), Array(17, 1), Array(18, 1)), TrailingMinusNumbers:=True
0
Comment
Question by:Justincut
  • 2
4 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 39753310
Your problem is in this code

Sub test()
Dim Prevday As String

Prevday = WorksheetFunction.workday(Date, -1)

Prevday = Format(Prevday, "DDMMYY")
End Sub

Open in new window


function workday is available from Excel 2007 onward you must have been probably using this now in Excel earlier version Excel 2003 or earlier this is where you will get
invalid property assignment

IS this possible ? what version of Excel your using ?
gowflow
0
 

Author Comment

by:Justincut
ID: 39753338
I am  using Excel 2007, I have run the same Macro for months without problem and have not changed the Code
0
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 39753354
I just tested it in 2007 and no problem.
Can you post the whole code maybe the variable is getting changed somewhow ...

gowflow
0
 
LVL 6

Expert Comment

by:ButlerTechnology
ID: 39753598
Can you double check that you aren't missing a library on the VBA side?  I have run into issues with code giving errors like the one that you mention when the application was used in a high version and the Library for the new version is being referenced.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel formula Sumif not working 4 28
VBA Fill Blanks with text from another cell 6 23
Excel VBA - Constants 4 17
Formula help - MIN 7 17
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question