Public Sub CompilaPreventivo()
Dim wmodulo As Object
Dim tabella2, tabella3 As Table
Set wmodulo = CreateObject("Word.Application")
filepath = ActiveSheet.Range("A14").Value
wmodulo.Application.Documents.Open filepath & "Quotazione.doc"
With wmodulo
.Selection.Goto What:=wdGoToBookmark, Name:="NumQuot"
.Selection.InsertAfter Range("L2")
If Range("t3").Value = "Not Applicable" And Range("u3") = "Not Applicable" Then
Set tabella2 = ActiveDocument.Tables(4) ' <-----errore!
Set tabella3 = ActiveDocument.Tables(5)
tabella2.Delete
tabella3.Delete
ElseIf Range("t3") <> "Not Applicable" And Range("u3").Value = "Not Applicable" Then
Set tabella3 = ActiveDocument.Tables(5)
tabella3.Delete
End If
.Application.Visible = False
.Application.Documents.Close
.Quit
End With
Set wmodulo = Nothing
End Sub |