Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Compile Error on Macro

Posted on 2014-01-03
4
Medium Priority
?
280 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 31

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 31

Accepted Solution

by:
gowflow earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

971 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