Hello,
I am trying to write a code where it copies a number from a provided list, pastes the number in a cell, calculates to update, then saves that tab in a folder and breaks the links before saving the file. The macro repeats this process till there are no more numbers to copy. I am having issues on the saving portion of the macro. I added a step to copy the tab in a new book, break links and then save the file.
The first issue I have when it saves, is that it saves it as an XPS file. The second issue is that the loop fails and I get a Debug error. I am no where near familiar with VBA, i used some old coding from another macro and trying to fit into this, so my apologies in advanced if it is horrible. Below is the code so far. Thank you.
Sub CreateStoreTargets()
Set shtTarget = Worksheets("StoreLabor")
Do Until Sheets("VBA - Comp Store List").Range("B1") = ""
StoreID = Sheets("VBA - Comp Store List").Range("B1").Value
District = Sheets("VBA - Comp Store List").Range("C1").Value
Sheets("StoreLabor").Select
Cells.Select
With Selection.Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
Range("A2").Select
Sheets("VBA - Comp Store List").Select
Range("A1").Select
Selection.Copy
Sheets("StoreLabor").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Application.Calculate
Sheets("VBA - Comp Store List").Select
Range("A1:C1").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Sheets("StoreLabor").Select
Sheets("StoreLabor").Copy
' Define variable as an Excel link type.
astrLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
' Break the first link in the active workbook.
ActiveWorkbook.BreakLink _
Name:=astrLinks(1), _
Type:=xlLinkTypeExcelLinks
ActiveSheet.ExportAsFixedFormat Type:=xlExcelLinks, Filename:=strFilePath1 & StoreID & strFilePath2 & strReportTitle1 & StoreID & strReportTitle2 & strDateFooter & strFilePath3, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Loop
ThisWorkbook.Saved = False
Application.Quit
End Sub
I am trying to write a code where it copies a number from a provided list, pastes the number in a cell, calculates to update, then saves that tab in a folder and breaks the links before saving the file. The macro repeats this process till there are no more numbers to copy. I am having issues on the saving portion of the macro. I added a step to copy the tab in a new book, break links and then save the file.
The first issue I have when it saves, is that it saves it as an XPS file. The second issue is that the loop fails and I get a Debug error. I am no where near familiar with VBA, i used some old coding from another macro and trying to fit into this, so my apologies in advanced if it is horrible. Below is the code so far. Thank you.
Sub CreateStoreTargets()
Set shtTarget = Worksheets("StoreLabor")
Do Until Sheets("VBA - Comp Store List").Range("B1") = ""
StoreID = Sheets("VBA - Comp Store List").Range("B1").Value
District = Sheets("VBA - Comp Store List").Range("C1").Value
Sheets("StoreLabor").Select
Cells.Select
With Selection.Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
Range("A2").Select
Sheets("VBA - Comp Store List").Select
Range("A1").Select
Selection.Copy
Sheets("StoreLabor").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Application.Calculate
Sheets("VBA - Comp Store List").Select
Range("A1:C1").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Sheets("StoreLabor").Select
Sheets("StoreLabor").Copy
' Define variable as an Excel link type.
astrLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
' Break the first link in the active workbook.
ActiveWorkbook.BreakLink _
Name:=astrLinks(1), _
Type:=xlLinkTypeExcelLinks
ActiveSheet.ExportAsFixedFormat Type:=xlExcelLinks, Filename:=strFilePath1 & StoreID & strFilePath2 & strReportTitle1 & StoreID & strReportTitle2 & strDateFooter & strFilePath3, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Loop
ThisWorkbook.Saved = False
Application.Quit
End Sub