+ Reply to Thread
Results 1 to 5 of 5

Script to open filename with suffix at the end of it?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    298

    Script to open filename with suffix at the end of it?

    This is the plain text version of what the script needs to do:

    1. Capture current workbook name and save as variable

    2. Open C:\files\(saved variable)001.xls

    3. Make (saved variable)001.xls the active window

    Then from here on out I will take over with the rest of the script I already have.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Script to open filename with suffix at the end of it?

    Maybe:

    Sub ks100()
    Dim x As String
    Dim y As String
    x = ActiveWorkbook.Path
    y = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
    Workbooks.Open "\" & x & y & "001.xls"
    End Sub

  3. #3
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    298

    Re: Script to open filename with suffix at the end of it?

    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe:

    Sub ks100()
    Dim x As String
    Dim y As String
    x = ActiveWorkbook.Path
    y = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
    Workbooks.Open "\" & x & y & "001.xls"
    End Sub
    Thanks, but unfortunately the active workbooks path is not the same as where its 001 counterpart is stored. The 001 copies are all stored in C:\files, so how would that change the formula?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Script to open filename with suffix at the end of it?

    Sub ks100()
    Dim x As String
    Dim y As String
    x = "C:\files" 'here
    y = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
    Workbooks.Open "\" & x & y & "001.xls"
    End Sub

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,719

    Re: Script to open filename with suffix at the end of it?

    Sub getname()
    Dim wbTarget As Workbook
    Dim wbThis As Workbook
    Dim strName As String
    Set wbThis = ActiveWorkbook
    strName = ActiveWorkbook.Name
    strName = Left(strName, Len(strName) - 4)
    MsgBox (strName)
    Set wbTarget = Workbooks.Add
        With wbTarget
            .SaveAs Filename:="C:\files\" & strName & "001.xls"
        End With
    wbTarget.Activate
    End Sub
    Last edited by alansidman; 12-12-2013 at 01:58 PM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 14
    Last Post: 08-17-2012, 10:54 AM
  2. VBA script- save file with current filename
    By -James_ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-06-2012, 04:10 PM
  3. How to close open workbooks from an application get open filename call ?
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2011, 10:41 PM
  4. set filename to <filename-date> on open
    By bob engler in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-13-2006, 12:15 AM
  5. script to change filename
    By jeramie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2006, 05:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1