
Sub Scrivi_in_file_esistente()
Dim applWord As Object
Dim docWord As Object
Dim a1 As Excel.Name
Dim i As Integer
'set the Application object variable to create a new instance of Word:
Set applWord = CreateObject("Word.Application")
'make the Word window visible:
applWord.Visible = True
'maximize Word window:
'replaced the Word's built-in constant wdWindowStateMaximize with its numerical value 1.
applWord.WindowState = 1
'opens an existing word document from a defined folder:
Set docWord = applWord.Documents.Open("C:Users...Modello.docx")
For i = 1 To 4
docWord.Bookmarks("a" & i).Range.Text = Sheets("Ingresso dati").Cells(2, i + 1).Value
Next i
'close and save the document:
docWord.SaveAs Filename:="C:Users...Offerta " & Sheets("Ingresso dati").Cells(2, 2).Value & ".docx"
docWord.Close
'quit the word application:
applWord.Quit
'clear the object variables:
Set docWord = Nothing
Set applWord = Nothing
End Sub |
Sub intervallo()
Dim rig As Integer
Dim col As Integer
Dim rigT As Integer
Dim colT As Integer
Dim arr() As Variant
Sheets("foglio1").Select
'rig = Selection.Row
'col = Selection.Column
rigT = Range(Range("a1"), Range("a1").End(xlDown)).Count ' Selection.Rows.Count
colT = Range(Range("a1"), Range("a1").End(xlToRight)).Count 'Selection.Columns.Count
'rigT = rigT + 1
'col = 26
ReDim arr(rigT, colT)
For i = 1 To rigT
For a = 1 To colT
arr(i, a) = Cells(i, a)
Next a
Next i
Call stampaW(arr, rigT, colT) 'rig, 'col,
Debug.Print rig & " - " & col & " - " & rigT & " - " & colT & " - "
End Sub
Sub stampaW(arr As Variant, rt As Integer, ct As Integer) ',rt As Integer, ct As Integer
Dim appW As Word.Application
Dim docW As Word.Document
Dim tblW As Word.Table
Dim rangeW As Word.Range
Dim i As Integer
Dim a As Integer
Set appW = CreateObject("word.application")
Set docW = appW.Documents.Add
Set rangeW = docW.Range(0, 0)
Set tblW = docW.Tables.Add(rangeW, rt, ct)
With tblW
For i = 1 To rt
For a = 1 To ct
.Cell(i, a).Range.InsertAfter CStr(arr(i, a))
Next a
Next i
.Columns.AutoFit
End With
appW.Visible = True
Set appW = Nothing
Set docW = Nothing
End Sub
|
