Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2016, 09:16 AM
silentwolf silentwolf is offline Runtime Error 5834 Style? Windows 7 64bit Runtime Error 5834 Style? Office 2010 64bit
Novice
Runtime Error 5834 Style?
 
Join Date: Dec 2016
Location: Austria
Posts: 16
silentwolf is on a distinguished road
Default Runtime Error 5834 Style?

Hi all I am new here,

and have already a question regardig a macro..
Unfortunatelly I am pretty new to word vba and can not finde a solution to this problem.
I like to write data from access to word .. the following code I got from a book but I recieve a error object not found..

Code:
Private Sub FillWithTypeText()

On Error GoTo ErrorHandler
    Dim appWord As Word.Application
    Dim doc As Word.Document
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    
    Set appWord = GetObject(, "Word.Application")
    Set doc = appWord.Documents.Add

'insert format document titel
    With appWord.Selection
        .TypeText "Aktuelle Kontakte mit " _
            & Format(Date, "Long Date")
        .TypeParagraph
        .MoveLeft Unit:=wdWord, count:=11, _
            Extend:=wdExtend
        .Font.Size = 14
        .Font.Bold = wdToggle
        .MoveDown Unit:=wdLine, count:=1
    End With
    
'insert two column table to hold contact data(one column for contact names, the other for user comments)
    doc.Tables.Add Range:=Selection.Range, _
        NumRows:=1, _
        NumColumns:=2, _
        DefaultTableBehavior:=wdWord9TableBehavior, _
        AutoFitBehavior:=wdAutoFitFixed
        
    With appWord.Selection.Tables(1)
        If .Style <> "Table Grid" Then
            .Style = "Table Grid"
        End If
        
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
    End With
    
'insert contact Data from Access table into Word table:
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("tblKunden")
    Do While Not rst.EOF
        With appWord.Selection
            .TypeText rst![kunKundenAnzeigen]
            .MoveRight Unit:=wdCell, count:=2
        End With
        rst.MoveNext
    Loop
    
'Delete the last names alphabetically:
    doc.Tables(1).Select
    appWord.Selection.Sort excludeheader:=False, _
        fieldnumber:="Column 1", _
        sortfieldtype:=wdSortFieldAlphanumeric, _
        SortOrder:=wdSortOrderAscending
        
ErrorHandlerExit:
    Set appWord = Nothing
    Exit Sub
    
ErrorHandler:
    If Err = 429 Then
    
'Word is not running: open Word with createObject:
    Set appWord = CreateObject("Word.Application")
    Resume Next
    Else
        MsgBox "Error No: " & Err.Number _
        & " ; Description: " & Err.Description
        Resume ErrorHandlerExit
    End If
    
End Sub
The code jumpes from the line in red into the MsgBox Error No....



So what am I missing here in this code? The code is writen in VBA 2007 ... and I got 2010 but not sure if that makes a difference.

Maybe someone knows what has to be changed so the code can run.

Many thanks in advance!!

Silentwolf :-)
Reply With Quote
  #2  
Old 12-09-2016, 04:06 PM
macropod's Avatar
macropod macropod is offline Runtime Error 5834 Style? Windows 7 64bit Runtime Error 5834 Style? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The following works fine for me:
Code:
'insert format document titel
    With appWord.Selection
        .TypeText "Aktuelle Kontakte mit " & Format(Date, "Long Date")
        .TypeParagraph
        .MoveLeft Unit:=wdWord, Count:=11, Extend:=wdExtend
        .Font.Size = 14
        .Font.Bold = wdToggle
        .MoveDown Unit:=wdLine, Count:=1
        'insert two column table to hold contact data(one column for contact names, the other for user comments)
        .Tables.Add Range:=.Range, NumRows:=1, NumColumns:=2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
        With .Tables(1)
          .Style = "Table Grid"
          .ApplyStyleHeadingRows = True
          .ApplyStyleLastRow = False
          .ApplyStyleFirstColumn = True
          .ApplyStyleLastColumn = False
          .ApplyStyleRowBands = True
          .ApplyStyleColumnBands = False
        End With
    End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-09-2016, 11:34 PM
silentwolf silentwolf is offline Runtime Error 5834 Style? Windows 7 64bit Runtime Error 5834 Style? Office 2010 64bit
Novice
Runtime Error 5834 Style?
 
Join Date: Dec 2016
Location: Austria
Posts: 16
silentwolf is on a distinguished road
Default

Hi macropod,

thank you for your reply! So did you leave out the error handler with your code?
I have tried your code but with error handler and get still the same message..

Cheers
Reply With Quote
  #4  
Old 12-10-2016, 02:05 AM
macropod's Avatar
macropod macropod is offline Runtime Error 5834 Style? Windows 7 64bit Runtime Error 5834 Style? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I didn't bother with the error-handling, which should not have any effect on the error you say you were getting. Indeed, the code could be further simplified. For example' leaving aside all the DAO-related code:
Code:
Sub Demo()

    Dim appWord As New Word.Application
    appWord.Documents.Add

'insert format document titel
    With appWord.Selection
        .TypeText "Aktuelle Kontakte mit " & Format(Date, "Long Date")
        .TypeParagraph
        .MoveLeft Unit:=wdWord, Count:=11, Extend:=wdExtend
        .Font.Size = 14
        .Font.Bold = wdToggle
        .MoveDown Unit:=wdLine, Count:=1
        'insert two column table to hold contact data(one column for contact names, the other for user comments)
        .Tables.Add Range:=.Range, NumRows:=1, NumColumns:=2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
        With .Tables(1)
          .Style = "Table Grid"
          .ApplyStyleHeadingRows = True
          .ApplyStyleLastRow = False
          .ApplyStyleFirstColumn = True
          .ApplyStyleLastColumn = False
          .ApplyStyleRowBands = True
          .ApplyStyleColumnBands = False
        End With
    End With
    appWord.Visible = True
End Sub
Note: I wouldn't do my own coding your way - or the way I've outlined it in my replies. I've just tried to make minimal changes to your code.

If I were trying to start a new Word session only if Word wasn't already running, I'd use late binding code like:
Code:
Sub Demo()
Dim wdApp As Object, wdDoc As Object, bStrt As Boolean
' Test whether Word is already running.
On Error Resume Next
bStrt = False ' Flag to record if we start Word, so we can close it later.
Set wdApp = GetObject(, "Word.Application")
'Start Word if it isn't running
If wdApp Is Nothing Then
  Set wdApp = CreateObject("Word.Application")
  If wdApp Is Nothing Then
    MsgBox "Can't start Word.", vbExclamation
    Exit Sub
  End If
  ' Record that we've started Word, so we can terminate it later.
  bStrt = True
End If
On Error GoTo 0
wdApp.Visible = True
End Sub
or early binding code like:
Code:
Sub Demo()
Dim wdApp As Word.Application, wdDoc As Word.Document, bStrt As Boolean
' Test whether Word is already running.
On Error Resume Next
bStrt = False ' Flag to record if we start Word, so we can close it later.
Set wdApp = GetObject(, "Word.Application")
'Start Word if it isn't running
If wdApp Is Nothing Then
  Set wdApp = CreateObject("Word.Application")
  If wdApp Is Nothing Then
    MsgBox "Can't start Word.", vbExclamation
    Exit Sub
  End If
  ' Record that we've started Word, so we can terminate it later.
  bStrt = True
End If
On Error GoTo 0
wdApp.Visible = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-10-2016, 03:09 AM
silentwolf silentwolf is offline Runtime Error 5834 Style? Windows 7 64bit Runtime Error 5834 Style? Office 2010 64bit
Novice
Runtime Error 5834 Style?
 
Join Date: Dec 2016
Location: Austria
Posts: 16
silentwolf is on a distinguished road
Default

Hi,
thanks again for your reply!
I will have a look at your code in detail tomorrow!

Cheers!
Reply With Quote
  #6  
Old 12-11-2016, 04:18 PM
Guessed's Avatar
Guessed Guessed is online now Runtime Error 5834 Style? Windows 10 Runtime Error 5834 Style? Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,993
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

SilentWolf
If the error is occurring on the line you highlighted in Red then the most obvious conclusion would be that the Table style named "Table Grid" does not exist in your document.

In English versions of Word, this would surprise me because it is a built-in style name. However, perhaps your document is not created in English and that stylename is something else in your language. You can change the code to any Table stylename that does exist in your document.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 07-23-2017, 02:58 PM
silentwolf silentwolf is offline Runtime Error 5834 Style? Windows 7 64bit Runtime Error 5834 Style? Office 2010 64bit
Novice
Runtime Error 5834 Style?
 
Join Date: Dec 2016
Location: Austria
Posts: 16
silentwolf is on a distinguished road
Default

Hi Guessed,
thanks for your reply!
The code works now as I did change or added a line of code to reference to the active document.
However as I am pretty new to this forum I have not yet figured out how to set the solved icon to my threat.
Maybe someone could let me know so I am not bothering anyone with a solved threat here

Many thanks

Silentwolf
Reply With Quote
  #8  
Old 07-23-2017, 03:03 PM
silentwolf silentwolf is offline Runtime Error 5834 Style? Windows 7 64bit Runtime Error 5834 Style? Office 2010 64bit
Novice
Runtime Error 5834 Style?
 
Join Date: Dec 2016
Location: Austria
Posts: 16
silentwolf is on a distinguished road
Default

Oh this is an old thread.
it must be getting late here lol!
Sorry I completly forogt about this threat and thought it is a new one!! My appologies!
I guess I will look into it again and go through all your suggestions once again and try to work it out!

Cheers for helping!

Silentwolf
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VB runtime error in debugger...please help rivrgrl7 Excel Programming 0 08-03-2016 07:58 AM
Runtime Error 5834 Style? Runtime error R6034 tallon Excel 4 07-08-2016 09:24 AM
Runtime Error 5834 Style? runtime error 1004 gbaker Excel Programming 11 06-06-2012 05:23 AM
Runtime Error 5834 Style? Runtime error 91 waldux Word VBA 1 03-04-2011 11:25 PM
Runtime error 5487 - Word cannot complete the save to to file permission error franferns Word 0 11-25-2009 05:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft