+ Reply to Thread
Results 1 to 8 of 8

Script to SaveAs?

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

    Script to SaveAs?

    How would I go about saving a workbook as to a new location?

    The code would be immedietly following the file being saved over at its current location.

    Basically what is already scripted is:

    1. File is opened.
    2. Data is pasted from another spreadsheet.
    3. File is saved.
    4. File is closed.


    I need to add a step between 3 and 4 that would:

    Save file as (same file name) in R:\logs

    So in other words, it the final script needs to open a file, modify it, save over itself, then save a duplicate to a new location (also overwriting a file).

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Script to SaveAs?

    Regard step 3 and 4, maybe

    Please Login or Register  to view this content.

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

    Re: Script to SaveAs?

    Quote Originally Posted by JieJenn View Post
    Regard step 3 and 4, maybe

    Please Login or Register  to view this content.
    That ends up saving a workbook to R:\logs that is empty.

  4. #4
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Script to SaveAs?

    My code is only addressing step 3 and step 4.

  5. #5
    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 SaveAs?

    Can you provide a copy of the code you are using?

  6. #6
    Registered User
    Join Date
    01-21-2014
    Location
    Newhouse
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Script to SaveAs?

    Hi I have an issue with saving the word document with the value of a Cell, also I want to make it a loop, meaning it will create e.g. 60 letters with different info, and to save it with a cell value which is for every save different, please can someone help me? See code:

    Sub CertGenerator()

    On Error GoTo errorHandler

    Dim wdApp As Word.Application
    Dim myDoc As Word.Document
    Dim mywdRange As Word.Range
    Dim Customer As Excel.Range
    Dim Deliverynr As Excel.Range
    Dim POnumber As Excel.Range

    Set wdApp = New Word.Application
    With wdApp
    .Visible = True
    .WindowState = wdWindowStateMaximize
    End With
    'Set the cell you want to copy'
    Set myDoc = wdApp.Documents.Add(Template:="C:\Test\Authorisationform.doc")
    Set Customer = Sheets("Sheet1").Range("A2")
    Set Deliverynr = Sheets("Sheet1").Range("D2")
    Set POnumber = Sheets("Sheet1").Range("E2")
    Set Colnr = Sheets("Sheet1").Range("D2")
    'Set the bookmark names'
    With myDoc.Bookmarks
    .Item("Customer").Range.InsertAfter Customer
    .Item("Deliverynr").Range.InsertAfter Deliverynr
    .Item("POnumber").Range.InsertAfter POnumber
    .Item("Colnr").Range.InsertAfter Colnr
    End With
    'How to save word document'
    With wdApp.ActiveDocument
    wdDoc.SaveAs ("C:\Test\"".doc")
    .Close

    End With

    errorHandler:

    Set wdApp = Nothing
    Set myDoc = Nothing
    Set mywdRange = Nothing

    End Sub

  7. #7
    Registered User
    Join Date
    09-27-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007, 2010, 2013
    Posts
    11

    Re: Script to SaveAs?

    Quote Originally Posted by JieJenn View Post
    Regard step 3 and 4, maybe

    Please Login or Register  to view this content.
    If the workbook has already been saved once, then ThisWorkbook.Name will include the extension (for example .xlsm), so you shouldn't add the extension in your filename string.
    Stefan Kemp
    Excel Developers Ltd

  8. #8
    Registered User
    Join Date
    01-21-2014
    Location
    Newhouse
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Script to SaveAs?

    Hi Stefan,

    Thank you for you reply, although i am trying to save it to a .doc document and to take the name from Cell D1 till D65. You have an idea? SO the result will be that I have 65 documents saved with the value of cell D1 till D65, hope this helps

+ 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. A script withing a script ..
    By xatomicx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-01-2013, 10:42 AM
  2. Integrating Mainframe emulator script with excel's vba script
    By Himanshu Mishra in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2012, 10:30 AM
  3. Create VBA script to short, dedicated button in excel for script?
    By realized in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2009, 11:54 PM
  4. Remove Book1 After Script SaveAs
    By edrichard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2009, 06:42 PM
  5. Script that edits the text printed on the button that runs the script
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2008, 02:41 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