Salve a tutti, ho creato un semplice codice che permette di generare documenti word, all'interno dei quali vengono incollate, sotto forma di tabella, selezioni del documento excel di partenza. Tuttavia, proprio in corrispondenza dell'istruzione che copia il range di excel in word, sotto forma di tabella, l'applicazione si blocca e compare il seguente errore: "Error 4605 - This command is not available" . La cosa che mi incuriosisce è che l'errore non avviene tutte le volte che faccio partire l'applicazione: a volte si, a volte no (senza apparente ragione). Inoltre, avviando il debug e rimettendo l'applicazione nuovamente in esecuzione (senza quindi toccare nulla nel codice), il più delle volte questa riprende tranquillamente. Di seguito riporto l'estratto del codice, sperando che possiate aiutarmi nel capire dove sbaglio. Grazie mille.
L'istruzione a cui viene generato l'errore è la seguente:
Report_i.Bookmarks("TABLE").Range.PasteAppendTable
Codice PHP:
Dim SCH1 As Double
Dim ECH1 As Double
Dim DATE1 As String
Dim ITR1 As Double
Dim STNUM1 As Double
SCH1 = SCH1_TB.Value ECH1 = ECH1_TB.Value DATE1 = DATE1_TB.Value ITR1 = ITR1_TB.Value STNUM1 = -Int((SCH1 - ECH1) / CSTEP)
For i = 0 To STNUM1 - 1
SCH_i = SCH1 + i * CSTEP ECH_i = SCH_i + CSTEP
FileCopy MODPATH, CurDir & "\REPORT\TO0001-06-" & SCH_i & "-" & ECH_i & "-" & WBS & ".docx"
Set WordApp = CreateObject("Word.Application")
Set Report_i = WordApp.Documents.Open(CurDir & "\REPORT\TO0001-06-" & SCH_i & "-" & ECH_i & "-" & WBS & ".docx")
Report_i.Bookmarks("WBS1").Range.Text = WBS Report_i.Bookmarks("TRACK1").Range.Text = TRACK
Report_i.Bookmarks("SCH1").Range.Text = "From Pk " & Format(SCH_i, ["00+000"])
Report_i.Bookmarks("ECH1").Range.Text = "To Pk " & Format(ECH_i, ["00+000"])
Report_i.Bookmarks("DATE1").Range.Text = DATE1
Report_i.Bookmarks("ITR1").Range.Text = ITR1
Report_i.Bookmarks("WBS2").Range.Text = WBS Report_i.Bookmarks("TRACK2").Range.Text = TRACK
Report_i.Bookmarks("SCH2").Range.Text = "From Pk " & Format(SCH_i, ["00+000"])
Report_i.Bookmarks("ECH2").Range.Text = "To Pk " & Format(ECH_i, ["00+000"])
Report_i.Bookmarks("DATE2").Range.Text = DATE1
Report_i.Bookmarks("ITR2").Range.Text = ITR1
For j = 10 To 65530
If Sheets("ABT").Cells(j, 1) > SCH_i Then
SRANGE_i = j - 1
Exit For
Else
End If
Next
For j = 10 To 65530
If Sheets("ABT").Cells(j, 1) > ECH_i Then
ERANGE_i = j
Exit For
Else
End If
Next
Sheets("ABT").Activate
Range("A" & SRANGE_i & ":" & "U" & ERANGE_i).Copy
Report_i.Bookmarks("TABLE").Range.PasteAppendTable
WordApp.Selection.Tables(1).Rows(4).Delete
Application.CutCopyMode = False
SHEET_i = SCH_i / CSTEP + 1
Sheets("D" & SHEET_i).Activate
ActiveSheet.ChartObjects("ALI").Activate
ActiveChart.ChartArea.Copy
Report_i.Bookmarks("ALICHART").Range.Paste
ActiveSheet.ChartObjects("LEV").Activate
ActiveChart.ChartArea.Copy
Report_i.Bookmarks("LEVCHART").Range.Paste
ActiveSheet.ChartObjects("CAN").Activate
ActiveChart.ChartArea.Copy
Report_i.Bookmarks("CANCHART").Range.Paste
ActiveSheet.ChartObjects("GAU").Activate
ActiveChart.ChartArea.Copy
Report_i.Bookmarks("GAUCHART").Range.Paste
Application.CutCopyMode = False
Report_i.Save
Report_i.ExportAsFixedFormat Left(Report_i.FullName, InStrRev(Report_i.FullName, ".") - 1), 17
Report_i.Application.Quit
Next