Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compile Error on Macro

Posted on 2014-01-03
4
Medium Priority
?
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

721 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