+ Reply to Thread
Results 1 to 12 of 12

Open and Save Using VBA

  1. #1
    Forum Contributor
    Join Date
    12-22-2004
    Location
    Kokomo, Indiana
    Posts
    236

    Question Open and Save Using VBA

    I am using Excel 2010 running in Windows XP. I would like to depress a command button which will allow me to open an Excel file. Once the file is open I would like to save it immediately ensuring the original file isn't changed. How can I programmatically do this using VBA? The name of my original file is called databaseFile and has an extension of xlsx.
    Last edited by ajocius; 12-15-2012 at 08:17 AM.

  2. #2
    Forum Contributor
    Join Date
    12-22-2004
    Location
    Kokomo, Indiana
    Posts
    236

    Re: Open and Save Using VBA

    I neglected to mention the need to change the name of the saved file to something else. Sorry.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Open and Save Using VBA

    Hi, ajocius,

    assuming that both workbooks are located in the very same folder:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Contributor
    Join Date
    12-22-2004
    Location
    Kokomo, Indiana
    Posts
    236

    Re: Open and Save Using VBA

    Holger, I'm navigating to a different folder and open the databaseFile. Each week I make some changes and Save As with a suffix (date). The new file now is saved in another folder which contains data files for the following weeks changes.

    Tony

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Open and Save Using VBA

    Hi, Tony,

    I'm navigating to a different folder
    Is that always the same folder (can be laid down in code) or do you wish to have a Dialog to pick the file?
    The new file now is saved in another folder
    Always the same folder or switching from month to month or year to year?

    Ciao,
    Holger

  6. #6
    Forum Contributor
    Join Date
    12-22-2004
    Location
    Kokomo, Indiana
    Posts
    236

    Re: Open and Save Using VBA

    Holger,

    I would like to have a Dialog to pick the file. At the beginning of the year I make 52 folders which represent each week. Each folder has datafiles which I accumulate throughout the week. I put bits of data from each file and place into the database file. I'm always changing from one folder this week to another next week.

    Tony

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Open and Save Using VBA

    Hi, Tony,

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Ciao,
    Holger

  8. #8
    Forum Contributor
    Join Date
    12-22-2004
    Location
    Kokomo, Indiana
    Posts
    236

    Re: Open and Save Using VBA

    Holger,

    Sweet, this is what the doctor ordered. Awesome. One last request. Is it possible to check MyDocument folder and only open Excel files? That would make this go from 95% to 100%.

    Tony

  9. #9
    Forum Contributor
    Join Date
    12-22-2004
    Location
    Kokomo, Indiana
    Posts
    236

    Re: Open and Save Using VBA

    Oh I forgot yet again. I'm using the SaveAs3 function.

    Tony

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Open and Save Using VBA

    Hi, Tony,

    no problem with that.

    Please Login or Register  to view this content.
    If you cancel the saving part the workbook stays open - please inform me if you wish to close it in this special case (just a small amendment in the If-clause).

    Ciao,
    Holger

  11. #11
    Forum Contributor
    Join Date
    12-22-2004
    Location
    Kokomo, Indiana
    Posts
    236

    Re: Open and Save Using VBA

    Holger,

    [SOLVED]


    This is precisely what I needed. Great job in helping this engineer do his job. Consider this problem solved. Hope you have a wonderful day. Take care and God bless.

    Tony

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Open and Save Using VBA

    Hi, Tony,

    glad if I could have been of some help. Could you please mark this thread as solved (according to FAQ) although you´ve already done it in the post? TIA.

    Holger

+ Reply to Thread

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.6.0 RC 1