+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    09-17-2009
    Location
    Naperville, IL
    MS-Off Ver
    Excel 2003
    Posts
    1

    Macro question "file name"

    I have a question on the file name.

    I constructed a macro that basically extracts data from one spreadsheet and puts it on a new spreadsheet in a different format.

    In order for my macros to function the orginal spreadsheet must be named Modified RQFR.xls

    My colleagues often rename the sheet to a different name so they know what data is on it. I've instructed them to rename the sheet back when extracting the data.

    My question is if there's a way around this so that the orginal sheet (the one that contains the macros) can named anything and have the macro still function?

    Here's the macro.

    Code:
    Sub SetupQuote()
    Set NewBook = Workbooks.Add
    With NewBook
    .Title = "Empowerment Quote"
    .SaveAs Filename:="Empowerment Quote.xls"
    End With
    
    Windows("Modified RQFR.xls").Activate
    Range("F5").Select
    Selection.Copy
    Windows("Empowerment Quote.xls").Activate
    Range("A4").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    
    End Sub
    Last edited by DonkeyOte; 10-07-2009 at 12:12 PM. Reason: tags added to OP

  2. #2
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: Macro question "file name"

    instead of windows(file_name) put windows(1) , windows(2) .. window(1) is always the active window

    Code:
    Sub SetupQuote()
    Set NewBook = Workbooks.Add
    With NewBook
    .Title = "Empowerment Quote"
    .SaveAs Filename:="Empowerment Quote.xls"
    End With
    
    Windows(2).Activate
    Range("F5").Select
    Selection.Copy
    Windows(2).Activate
    Range("A4").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Last edited by Shijesh Kumar; 09-17-2009 at 02:00 PM.

  3. #3
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Macro question "file name"

    Assuming that Modified RQFR.xls (or whatever its name is) is open to the proper sheet before this code executes, then
    Code:
    Sub SetupQuote()
        Dim wks As Worksheet
        Dim wkbNew As Workbook
        
        Set wks = ActiveSheet
        
        Set wkbNew = Workbooks.Add
        With wkbNew
            .Title = "Empowerment Quote"
            .SaveAs Filename:="Empowerment Quote.xls"
        End With
    
        ActiveSheet.Range("A4").Value = wks.Range("F5").Value
    
        ....
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

Thread Information

Users Browsing this Thread

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

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.2.0