+ Reply to Thread
Results 1 to 7 of 7

Save worksheet to document file name

  1. #1
    Registered User
    Join Date
    09-02-2008
    Location
    Holland
    Posts
    11

    Question Save worksheet to document file name

    Hi,

    I have a macro called "Rapportage" stored in an Excel file called "Index".

    This file is like a database and contains links to other xls files, e.g. "datasheet1".

    When I run the macro Rapportage inside datasheet1 (Index file is open at the time), a "new workbook" is made with some data from datasheet1.
    After that the file is saved and closed to a specific directory. (e.g. /rapportages/..)

    I need this "new workbook" to have the same name as the datasheet...

    this I tried with "ActiveWorkbook.name"

    But instead the workbook is called index, the workbook name the macro is stored in.

    Can anybody give me a tip, how I can save the new workbook with the workbook name the macro is ran from (datasheetX), and not the workbook the macro is stored in (index)?

    thanks

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Welcome to the forum.
    Please Login or Register  to view this content.
    ... is the name of the workbook the code is running in.

  3. #3
    Registered User
    Join Date
    09-02-2008
    Location
    Holland
    Posts
    11
    Hey shg,

    Thanks for the quick reply!

    When I store this macro inside the worksheet index,

    Please Login or Register  to view this content.
    but run it in the worksheet datasheet, the filename of the "new worksheet" is still index.xls

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    I misunderstood your question, sorry.

    You need to get the name of the workbook the code is operating on (not 'running in'). I can't tell you how without seeing your code.
    Last edited by shg; 09-02-2008 at 01:38 PM.

  5. #5
    Registered User
    Join Date
    09-02-2008
    Location
    Holland
    Posts
    11
    sorry if I wasn't clear. The code is stored in index.xls but is operating on datasheet1.xls (name differs per file). I don't have the entire code at hand but this is what it comes down to :


    Stored in index.xls
    Please Login or Register  to view this content.

    Ctrl+r is pressed in datasheet1.xls. This currently saves the new workbook under the name index.xls

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Maybe like this:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-02-2008
    Location
    Holland
    Posts
    11
    Hi shg,

    Excellent! Thanks for this code. Initially it didn't work because of a "same document name" coflict .. But I added a prefix to the new document name, and it works like a charm!

+ 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. Using String as filename in Save As not recognised by Dir
    By NoCanDo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2008, 05:49 PM
  2. Save Worksheet with Cell References
    By HKExcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-24-2007, 08:55 PM
  3. Extra tabs in Tab delimited text file from Excel worksheet
    By Ramya Dasaratha in forum Excel General
    Replies: 0
    Last Post: 04-19-2007, 11:53 AM
  4. save a worksheet as xps
    By stevis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2007, 06:00 AM
  5. Replies: 0
    Last Post: 04-12-2007, 11:24 PM

Tags for this Thread

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