2 Replies - 486 Views - Last Post: 18 August 2012 - 02:50 PM Rate Topic: -----

#1 achavez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-August 12

Opening YYYMMDD.CSV file referring to "ASOFDATE" macro

Posted 17 August 2012 - 05:12 PM

Hello, i am stuck pls help:

Trying to open a file referring to a ASOFDATE which is cell J18
Although the format of the date is: 8/17, would need the vba to open the file "notes_YYYYMMDD.csv" referring to the as of date / J18

Here is where im stuck!
Thank you!
Sub ImportNotesPosition()
'
' ImportNotesPosition Macro
'
Workbooks.Open Filename:="G:\imas\Downloads\Treasury\Notes_" & Format(Date, "asofdate") & ".csv"
                
        
End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Opening YYYMMDD.CSV file referring to "ASOFDATE" macro

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Opening YYYMMDD.CSV file referring to "ASOFDATE" macro

Posted 18 August 2012 - 08:57 AM

why not using directly the format string you want ?
Workbooks.Open Filename:="G:\imas\Downloads\Treasury\Notes_" & Format(Date, "YYYYMMDD") & ".csv"



Also, please use code tags when you post code ( code tags : [code ] [/ code] -without spaces). There is also a button at the top of the editor.
Was This Post Helpful? 0
  • +
  • -

#3 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 805
  • Joined: 16-September 09

Re: Opening YYYMMDD.CSV file referring to "ASOFDATE" macro

Posted 18 August 2012 - 02:50 PM

Just throwing out that I personally like to convert the date value to a date before hand and you really don't want to use the word date as a variable. I would use


Dim dteDate as string 'Or Dim as date if you have the right references
Workbooks.Open Filename:="G:\imas\Downloads\Treasury\Notes_" & Format(DateValue(dteDate), "YYYYMMDD") & ".csv"       



The DateValue converts to date before in case it's a text field that would throw an error
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1