PDA

View Full Version : vba add-in will not bring new document to front



nidi
06-26-2015, 08:03 AM
Hi all vba-cracks

I've built a word Add-in with a Ribbon.
On this, i call the template letter.dotx with a button
Now, wenn i push the Ribbon-button "start letter.dotx" i get a new window "document99.docx", everything is alright except the window "document99.docx" is always behind all the others.
However i use ActiveWindow and ActiveDocument, is it not possible for me to bring the document99.docx to the front.

Have you any tipps please? I'm not really a programmer.
My vba-code is:


Static Sub btnwork()

Set btnworkWordApp = CreateObject("Word.Application")

Select Case ribBtnContent
Case 1
BtnTemplatesFilepath = sSysTemplatePathComplete & ("\") & sBtn1Content
Case 2
BtnTemplatesFilepath = sSysTemplatePathComplete & ("\") & sBtn2Content 'this is configuring the letter.dotx for the call
Case 3
BtnTemplatesFilepath = sSysTemplatePathComplete & ("\") & sBtn3Content
Case 4
BtnTemplatesFilepath = sSysTemplatePathComplete & ("\") & sBtn4Content
Case 5
BtnTemplatesFilepath = sSysTemplatePathComplete & ("\") & sBtn5Content
Case 6
BtnTemplatesFilepath = sSysTemplatePathComplete & ("\") & sBtn6Content
End Select

btnworkWordApp.Documents.Add (BtnTemplatesFilepath) 'Das Dokument erstellen
btnworkWordApp.Visible = True

btnworkWordApp.Activate 'Aktiviere das letzterstellte Dokument

????? How to bring now the window document99.docx (or any other number) from back to the front????

'Errors abfangen
Exit Sub
errbtnwork:
MsgBox "Die Vorlage kann nicht aufgerufen werden" & vbCr & "Gründe: Vorlage nicht gefunden, Ordnerzugriff ungültig, Konfigurationsfehler", vbOKOnly, _
"Fehler beim Aufruf der Vorlage"

End Sub

SamT
06-26-2015, 04:24 PM
Dim NewDoc As Object
Set NewDoc = btnworkWordApp.Documents.Add (BtnTemplatesFilepath)
NewDoc.Activate