我在寻找我的问题的答案时发现了这个论坛。我发现这里发布的解决方案:
如何将每个工作表保存在 Excel 2010 工作簿中以使用宏分隔 CSV 文件?
我很抱歉没有评论那篇文章,但我找不到这样做的选项。所以,我发布这个问题。
我没有使用 zip 功能,只是创建了 CSV 文件并排除了一些工作表。如您所见,我也在做一些查找/替换功能和刷新数据。
它运行良好,但运行时间很长(1-1/2 小时)。如果我去掉保存功能,手动保存每张表,几分钟就可以完成。
是什么让它陷入困境?
下面的代码(抱歉格式不好)
Sub Worksheet_Macro()
' Category_Trail Macro
' Macro breaks category trail down into individual categories. TO BE USED ONLY IN THE "WORKSHEET" SHEET
'
'
Dim ws As Worksheet
Dim strMain As String
Dim lngCalc As Long
strMain = "C:\Users\David Cox\Documents\TotalOutdoorsman\Site\Inventory\Daily Upload Files\"
' Turn off calculations
With Application
.DisplayAlerts = False
.ScreenUpdating = False
lngCalc = .Calculation
.Calculation = xlCalculationManual
End With
'Update all Data
ActiveWorkbook.RefreshAll
'Copy and Paste Categories and create trail
Sheets("Worksheet").Select
Range("Ah2:Ah20000").Select
Selection.Copy
Range("Ai2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("Ai2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="/", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), _
TrailingMinusNumbers:=True
' Clean_Description Macro
' Macro copies and pastes product descriptions to new column and then cleans them of HTML code.
'
'
Range("AO2:AO20000").Select
Selection.Copy
Range("AP2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("AP:AP").Select
Selection.Replace What:="<br>", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="</br>", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
' Remove Appostrophies Macro
Sheets("RSR Inventory").Select
Columns("L:L").Select
Range("L5743").Activate
Selection.Replace What:="'", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets("Valor Inventory").Select
ActiveWindow.LargeScroll ToRight:=-1
Columns("C:C").Select
Selection.Replace What:="'", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
' Go back to Main Product Page
Sheets("MainProductPage").Select
'Turn Calculations back on
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.Calculation = lngCalc
End With
'Save before creating CSV Files
ThisWorkbook.Save
' Turn off calculations
With Application
.DisplayAlerts = False
.ScreenUpdating = False
lngCalc = .Calculation
.Calculation = xlCalculationManual
End With
'Save all CSV files
For Each ws In ActiveWorkbook.Worksheets
Select Case ws.Name
Case "Imported Product Data", "Sheet 2", "Sheet 3"
'do nothing for these sheets
Case Else
ws.SaveAs strMain & ws.Name, xlCSV
End Select
Next
'Turn Calculations back on
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.Calculation = lngCalc
End With
End Sub