VBA to open specified workbook and "Save As" a cell value .xlsx

SevenOut

Board Regular
Joined
Jan 7, 2020
Messages
82
Office Version
  1. 2013
Platform
  1. Windows
C2=Date (8.15.22) fore example.
I would like to create a button macro that opens a workbook (file path will be recorded on a "setup" worksheet, for example: Setup!A2) and save that workbook with the value of C2 & .xlsx (8.15.22.xlsx)

Ultimately there will be seven of these buttons, one for each day of the week. Each opening the exact same file, naming that file to each buttons corresponding date.
I would like the new file to remain open until manually closed as well.

I do have a macro workbook that does similar, creating a saved copy of the directed workbook for each day of the month. I am struggling adapting it however.
Any help would be appreciated.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Here is what I'm working with:

VBA Code:
Sub Sat_Button()
    Dim ws As Worksheet
    Dim wb As Workbook
    Dim rng As Range, c As Range
    Dim wbPath As String, NewPth As String
    Dim NewNm As String

    Set ws = ActiveSheet
    Application.ScreenUpdating = False
    With ws
        Set wb = Workbooks.Open(.Range("F160").Value)
        wbPath = wb.Path & "\"
        Set rng = .Range("V11")
        For Each c In rng.Cells
            If c <> "" Then
                wb.SaveAs (wbPath & "\" & c & ".xlsx")
            End If
        Next c
    End With
End Sub

F160= directory path of workbook to be opened
V11= name to save the workbook as (date in the 8.15.22 format)

I need the workbook that is opened to be "Save As" in the same directory, not a new directory.
So far,
VBA Code:
wb.SaveAs (wbPath & "\" & c & ".xlsx")
is flagged in the debugger.

Anyone with input??
 
Upvote 0
Troubleshot the problem, the V11 value was not formatted correctly. =TEXT function fixed and all works great.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top