Hello, i need help with 2 problems
1)
im coping excel ranges and inserting them on bookmars in a word document in a iterative way, the problem arises
when i try to format the pasted tables, only the first get changed and not all the chages are made by the code.
I really dont understand why it doesnt work
wordDoc.Bookmarks("tabInstADSLAITop").Range.PasteExcelTable False, False, False Application.CutCopyMode = False Set tbl = wordDoc.Tables(numTab) With tbl .Rows.HeightRule = wdRowHeightExactly .Rows.Height = 15.6 ' +- 0.55 cm .AutoFitBehavior (wdAutoContent) .AutoFitBehavior (wdAutoFitWindow) End With wordDoc.Bookmarks("instADSLAITop").Range.InsertAfter numInst
2)
for time to time i keep getting the error 462 The remote server machine does not exist or is unavailable at this line:
or this line:Set tbl = wordDoc.Tables(numTab)
wordDoc.Bookmarks("instADSLAITop").Range.InsertAfter numInst
Thanks
You'll have tlo show more of your code:
It's not clear which method you use to control Word: Getobjec, createobject or Word.application (early binding).
The origin of the variable 'numtab' isn't clear, neither is numinst's.
Edited my first response after re-reading.
How does early binding work? I always use the create/get object method
Last edited by docMed; 07-01-2011 at 03:02 PM.
This is how i do:
Private Sub CommandButton3_Click() fp_TemplateWord = Application.GetOpenFilename("Wordfiles (*.doc*;*.dot*)*.doc*,*.dot*", , "Abrir um Ficheiro Word...") If fp_TemplateWord = False Then Exit Sub Else LabelTemplateWord.Caption = GetFilenameFromPath(fp_TemplateWord) On Error Resume Next Set wdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then 'Word isn't already running Set wdApp = CreateObject("Word.Application") End If On Error GoTo 0 Set wdDoc = wdApp.Documents.Open(fp_TemplateWord) wdApp.Visible = True wdDoc.Activate End If End Sub
To achieve the same result:
But that leaves the questions about the variables unanswered.Sub snb() c00 = Application.GetOpenFilename("Wordfiles (*.doc*;*.dot*)*.doc*,*.dot*", , "Abrir um Ficheiro Word...") If c00 <> False Then With GetObject(c00) .Activate ' ==== your code .Close 0 End With End If End Sub
@docMed
Eaarly binding: activate the reference to a certain application in the VBEdior/menu Bar/ extra/references.
Having done that you can use this code:
Sub snb_early_binding() c00 = Application.GetOpenFilename("Wordfiles (*.doc*;*.dot*)*.doc*,*.dot*", , "Abrir um Ficheiro Word...") If c00 <> False Then word.documents.add c00 end if End Sub
Last edited by snb; 07-04-2011 at 05:06 AM.
The variable numTab is passed as argumente to the SUB, and it comes from a FOR loop.
it represents the position of the table at the word document.
I dont know any other way of selecting the table...
With latebinding you can't use Word constants like 'wdAutoContent'.
I didnt quite understand the meaning o late/early binding so i went here http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx but it didnt tell me how to do the early bind that i need for the code to work.
Its even possible? And if it is, how can i do this?
Thanks.
I explained that in post #5
i´ve changed the variables to
i wented to Tools->references and the microsoft word/excrel object library 12.0 was already set, so i think that the following already is early bindingDim wdDoc As word.Document Dim wdApp As word.Application
But in the form that im making when i summon the procedure that handles wordPrivate Sub CommandButton3_Click() fp_TemplateWord = Application.GetOpenFilename("Wordfiles (*.doc*;*.dot*)*.doc*,*.dot*", , "Abrir um Ficheiro Word...") ' If fp_TemplateWord = False Then Exit Sub Else LabelTemplateWord.Caption = GetFilenameFromPath(fp_TemplateWord) On Error Resume Next Set wdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then 'Word isn't already running Set wdApp = New word.Application End If On Error GoTo 0 Set wdDoc = wdApp.Documents.Open(fp_TemplateWord) wdApp.Visible = True wdDoc.Activate End If
i use wordDoc as Object because it gives error if i try to use word.Document !?Sub inserttable(wordDoc As Object, nomeServico As String, tipotabela As String, numInst As Integer, numTab As Integer, wdApp As Variant, tabela As Range)
Last edited by kronozord; 07-04-2011 at 12:45 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks