Consulting

Results 1 to 12 of 12

Thread: Solved: Syntax Question

  1. #1

    Solved: Syntax Question

    hi

    Workbooks("KPI 0044 internal Shortageswk" & CStr(VBAWeekNum(Now(), 1)) & ".xls")
    and line

    wbEXT = "C:\KPI 0015 external Shortageswk" & CStr(VBAWeekNum(Now(), 1))
    how can i change this to a diffrent permitation ie

    Workbooks("KPI 0044 wkno here internal Shortages" & CStr(VBAWeekNum(Now(), 1)) & ".xls")


    is it just as simple as
    Workbooks ("KPI 0044 wk" & CStr(VBAWeekNum(Now(), 1)) & "internal Shortages" & ".xls")
    Thanks

    Merc
    Last edited by mercmannick; 08-12-2006 at 11:14 AM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Assuming that VBAWeeknum is a function in your project, the only thing I can see is a possible extra space

    [vba]

    Workbooks("KPI 0044 wk" & CStr(VBAWeekNum(Now(), 1)) & " internal Shortages" & ".xls")
    [/vba]

  3. #3
    Xld

    yes vbaweeknum is a function in project

    for some reason VBA is putting that space in


    what i am asking if the weeknumber is in a diffrent place to
    Workbooks("KPI 0044 internal Shortageswk" & CStr(VBAWeekNum(Now(), 1)) & ".xls")
    maybe like

    below
    "KPI 0044 wk** internal Shortages"

    how would i code this

    Thanks

    Merc

  4. #4
    'open most recent book by weeknumber
        wbEXT = "C:\KPI 0015 external Shortageswk" & CStr(VBAWeekNum(Now(), 1))
        'open most recent book by weeknumber
        wbINT = "C:\KPI 0044 internal Shortageswk" & CStr(VBAWeekNum(Now(), 1))
    
        Workbooks.Open Filename:=wbINT    'open kpi 0044
        Workbooks.Open Filename:=wbEXT    'open kpi 0015
    Also if there wasnt a file with the right weeeknumber how could i add that a msgbox says "WkNo** is not Available"
    then exit Sub

    Merc

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Dir command is the simplest check
    [VBA]
    If Len(Dir("C:\Test.xls")) = 0 Then MsgBox "File not found"

    [/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'

  6. #6
    yes but how would you stop sub if not found

    Merc

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]
    If Len(Dir("C:\Test.xls")) = 0 Then
    MsgBox "File not found"
    Exit Sub
    End If

    [/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'

  8. #8
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Merc

    If your still having trouble with the space don't use CStr, you don't need it.

  9. #9
    Workbooks("KPI 0044 wk" & (VBAWeekNum(Now(), 1)) & _
     " internal Shortages" & ".xls")
    Norie so this will work like this

    Merc

  10. #10
    wbEXT = "C:\KPI 0015 wk" & (VBAWeekNum(Now(), 1)) & " external Shortages" & (".xls")
    Cool works a treat thanks

    Merc

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You don't actually need all the brackets.
    [VBA]
    wbEXT = "C:\KPI 0015 wk" & VBAWeekNum(Now(), 1) & " external Shortages" & ".xls"
    [/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'

  12. #12
    cool thnx md

    Merc

Posting Permissions

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