嗨 試圖獲得一些幫助以了解為什么這在我設定的宏中不起作用。除錯器導致問題的區域位于第二個 Selection.Formula 區域。
Sub PrintAllonges()
'
' PrintAllonges Macro
'
' Keyboard Shortcut: Ctrl Shift Y
'
Dim pdfName As String, FullName As String, Path As String, lRow As Long
Set oFSO = CreateObject("Scripting.FileSystemObject")
Path = CreateObject("WScript.Shell").specialfolders("Desktop")
' Create Desktop Folder if not exists
If oFSO.FolderExists(Path & "\Allonges") Then
Else
MkDir Path & "\Allonges"
End If
'Turn off Screen Update
Sheets("MissingAllonges").Select
lRow = Cells(Rows.Count, 1).End(xlUp).Row
MsgBox (lRow)
Sheets("AllongeTemplate").Select
Application.ScreenUpdating = False
For i = 2 To lRow
Range("G6").Select
Selection.Formula = "=MissingAllonges!I" & i
Range("E11").Select
Selection.Formula = _
"=TEXT(MONTH(MissingAllonges!D" & i & "),""mmmm"")&"" ""&DAY(MissingAllonges!D" & i & ")&"", ""&YEAR(MissingAllonges!D" & i & ")"""
pdfName = Sheets("AllongeTemplate").Range("H7").Value & " - " & Sheets("AllongeTemplate").Range("G6").Value & " Allonge"
FullName = Path & "\Allonges\" & pdfName & ".pdf"
ActiveWorkbook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FullName, OpenAfterPublish:=False
Next i
Application.ScreenUpdating = True
End Sub
我把它放進去并開始為我正在更新回圈的其他公式作業,但我無法讓它作業并且在語法上出錯。
uj5u.com熱心網友回復:
公式末尾有額外的引號。
修正后的公式為:
.Formula = "=TEXT(MONTH(MissingAllonges!D" & i & "),""mmmm"")&"" ""&DAY(MissingAllonges!D" & i & ")&"", ""&YEAR(MissingAllonges!D" & i & ")"
但我同意@BigBen 的公式可以簡化,即:
.Formula = "=TEXT(MissingAllonges!D" & i & ", ""mmmm d, yyyy"")"
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/386815.html
上一篇:使用單元格值更改圖表系列值
