Consulting

Results 1 to 7 of 7

Thread: Solved: open file with a date variable

  1. #1
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location

    Solved: open file with a date variable

    hi,

    i download a daily file that is in this format.
    i want to automate the download but i'm having trouble with the date
    HTML Code:
    http://xxxx.xxxx.com/xxxx_xxx/xxxx/xxxx/xxxx/xxxx_20090630.dat
    this is what i've tried
    [vba]
    Sub reportdate()
    dim mydat as string
    mydat = Format(Date,"yyyymmdd")
    Workbooks.Open Filename:= _
    HTML Code:
    http://xxxx.xxxx.com/xxxx_xxx/xxxx/xxxx/xxxx/xxxx_mydat.dat"
    [/vba]
    but i could not open the file. mydat does not show today's date at all.

    what am i missing?

    thanks
    zach

  2. #2
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    i didn't try hard enough
    this works now
    [vba]
    mydat = Format(Date, "yyyymmdd")
    myfile = "xxxx_" & mydat & ".dat"
    Workbooks.Open Filename:= _
    HTML Code:
    "http://xxxx.xxxx.com/xxxx_xxx/xxxx/xxxx/xxxx/" & myfile & " "
    [/vba]

    sorry for the post

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub Macro1()
    Dim MyDat As String
    MyDat = Format(Date, "yyyymmdd") & ".dat"
    MsgBox "http://xxxx.xxxx.com/xxxx_xxx/xxxx/xxxx/xxxx/xxxx_" & MyDat
    ActiveWorkbook.FollowHyperlink "http://xxxx.xxxx.com/xxxx_xxx/xxxx/xxxx/xxxx/xxxx_" & MyDat
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    deleted
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    hi malcolm,

    thanks for the solution. just a quick question:
    with your method, the file opens with notepad.
    with my method, the file opens with Excel.
    any insight as to why this would happen?

    thanks again
    zach

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Dat is normally a text file. Just use your original "Open" line (it was hidden on my screen)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    thanks malcolm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •