因此,我一直在使用宏将工作表另存为PDF,但现在我不再使用多个工作表,而是使用一个工作表,该工作表通过从单元格A1的下拉列表中提取所有需要的信息,然后根据下拉列表的单元格进行提取值,工作表上的其他字段会更新。
下面的宏用于逐页处理:
Sub SaveWorksheetsAsPDFs()
Dim sFile As String
Dim sPath As String
Dim wks As Worksheet
With ActiveWorkbook
sPath = .Path & "\"
For Each wks In .Worksheets
Select Case wks.Name
Case Else
'Code here to run on the other sheets
sFile = wks.Name & ".pdf"
wks.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sPath & sFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Select
Next wks
End With
End Sub
现在,既然我将所有内容都放在一张纸上,是否有办法从下拉菜单中逐项将其填充并自动另存为PDF?谢谢
答案 0 :(得分:1)
我认为这应该工作-您将要保存选项到数组,然后设置需要作为选项的单元格。在我的示例中,我在A1
表上使用了Sheet1
。根据需要进行调整:
Option Explicit
Sub loop_through_dropdown()
Dim inputRange
inputRange = Range("A1").Validation.Formula1
Dim inputs, temp_option As String
inputs = Split(inputRange, ",")
Dim i As Long
For i = LBound(inputs) To UBound(inputs)
temp_option = (Trim(inputs(i)))
'do something with temp_option
Debug.Print (temp_option)
Worksheets("Sheet1").Range("A1").Value = temp_option
' Now, the page should update with the data for that option. Now simply run the macro
Call SaveWorksheetsAsPDFs
Next i
End Sub