+ Reply to Thread
Results 1 to 12 of 12

Open and Save Using VBA

Hybrid View

  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:
    Sub ajocius_SaveAs()
    Dim wb As Workbook
    Set wb = Workbooks.Open("Database.xlsx")
    If Not wb Is Nothing Then
      wb.SaveAs Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5) & Format(Now, "yymmdd_hhnnss") & ".xlsx", FileFormat:=51
    Else
      MsgBox "Couldn`t find 'database.xlsx' in the directory of teh macro workjbook", vbInformation
    End If
    End Sub
    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 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

  8. #8
    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