VBA Open and Save As new name from Listed to another workbook

12Rev79

New Member
Joined
Mar 2, 2021
Messages
46
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi Experts,

Please I need your help for me to figure out of how to modify the code below.
The code execution, Open my file "Key support_DIV-CEGS-XS-AF-Fabrication.xlsx" then Save As with new name that are list in my "Extract.xlsx" in Column D, like;

Column D:
Ref Voucher
DIV-CEGS-XS-AF-1370
DIV-CEGS-XS-AF-1385

I want the code to open my file "Key support_DIV-CEGS-XS-AF-Fabrication.xlsx" Save As with the New name like
"Key support_DIV-CEGS-XS-AF-1370.xlsx" and change the value of Cell A5 "DIV-CEGS-XS-AF-1370" then save and close then go to next cell
"Key support_DIV-CEGS-XS-AF-1385.xlsx" and change the value of Cell A5 "DIV-CEGS-XS-AF-1385"
the code will stop up to the last value that is listed in my Column D.

VBA Code:
Sub Macro1()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim ws As Worksheet, KeyW As Workbook, KeyS As Worksheet, ls As Long, i As Integer
Dim path As String, keypath As String

path = "C:\Desktop\Fabrication" 'Link Folder data
keypath = "Key support_DIV-CEGS-XS-AF-Fabrication.xlsx"

Set ws = ThisWorkbook.Sheets(1) 'Set ur Sheet Name in "Extract.xlsx"
ls = ws.Cells(Rows.Count, "D").End(xlUp).Row

Set KeyW = Workbooks.Open(path & "\" & keypath) 'Open file "Key support_DIV-CEGS-XS-AF-Fabrication.xlsx"
Set KeyS = KeyW.Sheets(1) 'Set ur Sheet Name in "Key support_DIV-CEGS-XS-AF-Fabrication.xlsx"

For i = 2 To Application.CountA(ws.Range("D2:D" & ls))+1
With KeyS
.Range("A5").Value = Mid(ws.Range("D2").Value, 5, 20) 'Change the Cell A5 Value to CEGS-XS-AF-1370 and so on
KeyW.SaveCopyAs path & "\" & "Key support_" & ws.Range("D" & i).Value & ".xlsx" 'Save As a new file name like "Key support_DIV-CEGS-XS-AF-1370.xlsx" and so on.
End With
Next i
KeyW.Close False 'Close file "Key support_DIV-CEGS-XS-AF-Fabrication.xlsx"
MsgBox "Done"
End Sub


Thanks in advance for the help
12Rev79
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,224,875
Messages
6,181,516
Members
453,050
Latest member
Obil

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