Solved

Compile Error on Macro

Posted on 2014-01-03
4
273 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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 …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

730 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