0
我有以下代碼生成報告並將其複製到Notepad ++,但它不會根據需要保存它。任何人都可以幫忙嗎? 它沒有生成錯誤代碼。VBA另存爲在記事本+ +不起作用
Sub Main
Dim nppl
stattempname = ActiveDocument.FullName
stattempname = Replace(stattempname, ".pcb", "_STATS.txt")
On Error Resume Next
staFile = stattempname
Kill staFile
On Error GoTo 0
Dim objData As New MSForms.DataObject
Dim strText As String
strText = stattempname
objData.SetText strText
objData.PutInClipboard
STATCommand = ""
STATCommand = STATCommand & "Application.ExecuteCommand(""Reports"")" & vbCrLf
STATCommand = STATCommand & "ReportsDlg.SelectReportFilesForOutput.Selected(1) = true" & vbCrLf
STATCommand = STATCommand & "ReportsDlg.Ok.Click()" & vbCrLf
Application.RunMacro "",STATCommand
On Error Resume Next
nppl = Shell("C:\Program Files (x86)\Notepad++\notepad++.exe")
AppActivate nppl
SendKeys "^+s", True
SendKeys "^v~", True
SendKeys "%{F4}", True
nppl.SaveAs FileName:="" & stattempname
End Sub
你得到任何錯誤,如果你刪除所有'On Error'語句? – Verzweifler
爲什麼不直接從VBA編寫文本文件? – Comintern
如果刪除On Error語句,則不會出現錯誤。 – Dan