mariade
29-08-2006, 10:16
Salve ragazzi,
ho un problema nel creare il mio piccolo progetto, praticamente dovrei copiare alcuni dati da excel e inserirli in word, dove c'e' un testo e dei bookmarks.
Son riuscita a creare il collegamento tra excel e word, difatti si apre il documento word attraverso un tasto su excel che dovrebbe copiare in word dove ho inserito testi e bookmarks, ma non mi copia i dati, word e' vuoto.
Quando clicco Copy, mi esce run time error 13 Type mismatch, e mi seleziona questa riga :"wordApp.Selection.TypeText Text = "TelePhone Report"
Vi riporto tutto il codice che dovrebbe aprire il file word e copiare e incollare, quindi solo la seconda parte...
"Private Sub cmdCopy_Click()
Dim wordApp As Object
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
'Create a New Word Document
wordApp.Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
wordApp.Selection.TypeText Text = "TelePhone Report"
wordApp.Selection.Style = wordApp.ActiveDocument.Styles("Heading1")
wordApp.Selection.TypeParagraph
'Enter the date
wordApp.Selection.TypeText Text = "Received"
wordApp.Selection.InsertDateTime_
DateTimeFormat = "ddd,MMM dd,yyyy"
InsertAsField = False
DateLanguage = wdEnglishUK
CalendarType = wdCalendarWestern
InsertAsFullWidth = False
wordApp.Selection.TypeParagraph
wordApp.Selection.TypeText_
Text = "Dear Customer, we are sending you tha amount to pay and his details:"
wordApp.Selection.Style = wordApp.ActiveDocument.Styles("Heading2")
wordApp.Selection.TypeParagraph
'Create bookmark for CustomerName
With wordApp.ActiveDocument.Bookmarks.AddRange = wordApp.Selection.Range
Name = "CustomerName"
.DefaultsSorting = wdSortByName
.ShowHidden = False
End With
'Switch To Excel, copy data Customer
AppActivate "Microsoft Excel", False
Application.Goto Reference = "E3"
Selection.CopyText Appearance = xlScreen
'Switch to Word
AppActivate "Microsoft Word", False
'Go to Bookmark "CustomerName"
wordApp.Selection.Goto Name = "CustomerName"
'Paste data
wordApp.Selection.Paste
'Create bookmark for CustomerNumber
With wordApp.ActiveDocument.Bookmarks.AddRange = wordApp.Selection.Range
Name = "CustomerNumber"
.DefaultsSorting = wdSortByName
.ShowHidden = False
End With
'Switch To Excel, copy data Customer
AppActivate "Microsoft Excel", False
Application.Goto Reference = "D3"
Selection.CopyText Appearance = xlScreen
'Switch to Word
AppActivate "Microsoft Word", False
'Go to Bookmark "CustomerName"
wordApp.Selection.Goto Name = "CustomerNumber"
'Paste data
wordApp.Selection.Paste
'Create bookmark for Amount
With wordApp.ActiveDocument.Bookmarks.AddRange = wordApp.Selection.Range
Name = "Amount"
.DefaultsSorting = wdSortByName
.ShowHidden = False
End With
'Switch To Excel, copy data Customer
AppActivate "Microsoft Excel", False
Application.Goto Reference = "H3"
Selection.CopyText Appearance = xlScreen
'Switch to Word
AppActivate "Microsoft Word", False
'Go to Bookmark "CustomerName"
wordApp.Selection.Goto Name = "Amount"
'Paste data
wordApp.Selection.Paste
wordApp.Selection.TypeText_
Text = "Thanks,Regards Eircom "
wordApp.Selection.Style = wordApp.ActiveDocument.Styles("Heading3")
wordApp.Selection.TypeParagraph
wordApp.ChangeFileOpenDirectory localPath
'save Report
ActiveDocument.SaveAsFilename = "Eircom.doc"
FileFormat = wdFormatDocument
End Sub
"
Cosa dite??? :confused:
ho un problema nel creare il mio piccolo progetto, praticamente dovrei copiare alcuni dati da excel e inserirli in word, dove c'e' un testo e dei bookmarks.
Son riuscita a creare il collegamento tra excel e word, difatti si apre il documento word attraverso un tasto su excel che dovrebbe copiare in word dove ho inserito testi e bookmarks, ma non mi copia i dati, word e' vuoto.
Quando clicco Copy, mi esce run time error 13 Type mismatch, e mi seleziona questa riga :"wordApp.Selection.TypeText Text = "TelePhone Report"
Vi riporto tutto il codice che dovrebbe aprire il file word e copiare e incollare, quindi solo la seconda parte...
"Private Sub cmdCopy_Click()
Dim wordApp As Object
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
'Create a New Word Document
wordApp.Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
wordApp.Selection.TypeText Text = "TelePhone Report"
wordApp.Selection.Style = wordApp.ActiveDocument.Styles("Heading1")
wordApp.Selection.TypeParagraph
'Enter the date
wordApp.Selection.TypeText Text = "Received"
wordApp.Selection.InsertDateTime_
DateTimeFormat = "ddd,MMM dd,yyyy"
InsertAsField = False
DateLanguage = wdEnglishUK
CalendarType = wdCalendarWestern
InsertAsFullWidth = False
wordApp.Selection.TypeParagraph
wordApp.Selection.TypeText_
Text = "Dear Customer, we are sending you tha amount to pay and his details:"
wordApp.Selection.Style = wordApp.ActiveDocument.Styles("Heading2")
wordApp.Selection.TypeParagraph
'Create bookmark for CustomerName
With wordApp.ActiveDocument.Bookmarks.AddRange = wordApp.Selection.Range
Name = "CustomerName"
.DefaultsSorting = wdSortByName
.ShowHidden = False
End With
'Switch To Excel, copy data Customer
AppActivate "Microsoft Excel", False
Application.Goto Reference = "E3"
Selection.CopyText Appearance = xlScreen
'Switch to Word
AppActivate "Microsoft Word", False
'Go to Bookmark "CustomerName"
wordApp.Selection.Goto Name = "CustomerName"
'Paste data
wordApp.Selection.Paste
'Create bookmark for CustomerNumber
With wordApp.ActiveDocument.Bookmarks.AddRange = wordApp.Selection.Range
Name = "CustomerNumber"
.DefaultsSorting = wdSortByName
.ShowHidden = False
End With
'Switch To Excel, copy data Customer
AppActivate "Microsoft Excel", False
Application.Goto Reference = "D3"
Selection.CopyText Appearance = xlScreen
'Switch to Word
AppActivate "Microsoft Word", False
'Go to Bookmark "CustomerName"
wordApp.Selection.Goto Name = "CustomerNumber"
'Paste data
wordApp.Selection.Paste
'Create bookmark for Amount
With wordApp.ActiveDocument.Bookmarks.AddRange = wordApp.Selection.Range
Name = "Amount"
.DefaultsSorting = wdSortByName
.ShowHidden = False
End With
'Switch To Excel, copy data Customer
AppActivate "Microsoft Excel", False
Application.Goto Reference = "H3"
Selection.CopyText Appearance = xlScreen
'Switch to Word
AppActivate "Microsoft Word", False
'Go to Bookmark "CustomerName"
wordApp.Selection.Goto Name = "Amount"
'Paste data
wordApp.Selection.Paste
wordApp.Selection.TypeText_
Text = "Thanks,Regards Eircom "
wordApp.Selection.Style = wordApp.ActiveDocument.Styles("Heading3")
wordApp.Selection.TypeParagraph
wordApp.ChangeFileOpenDirectory localPath
'save Report
ActiveDocument.SaveAsFilename = "Eircom.doc"
FileFormat = wdFormatDocument
End Sub
"
Cosa dite??? :confused: