Results 1 to 2 of 2

Thread: Accessing Word from Visual Basic

  1. #1

    Thread Starter
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    why do you need to do this, if you need to change parameters then use the property equivelent:

    1. Open Word
    2. Record a new macro
    3. Open the Templates and Addins window
    4. Make any and all changes and click OK
    5. Open the VBA Editor, find the macro, and use the properties it set to change those setttintgs


    Other wise try this:
    Code:
    'copied from another thread and modified, not my code:
    'Mathew Gates code
    Public Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, ByVal _
    lpWindowName As String) As Long
    Public Declare Function SendMessageLong& Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long)
    Declare Function GetMenu Lib "user32" _
    (ByVal hwnd As Long) As Long
    Declare Function GetSubMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Declare Function GetMenuItemID Lib "user32" _
    (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Declare Function GetMenuItemCount Lib "user32" _
    (ByVal hMenu As Long) As Long
    Private Declare Function GetMenuString Lib "user32" _
    Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal _
    wIDItem As Long, ByVal lpString As String, ByVal nMaxCount _
    As Long, ByVal wFlag As Long) As Long
    
    Public Const WM_COMMAND = &H111
    
    Private Sub Command1_Click()
    Dim notepad As Long
    notepad = FindWindow("winword", vbNullString)
    Dim TheWindow As Long
    Dim aMenu As Long
    Dim mCount As Long
    Dim LookFor As Long
    Dim sMenu As Long
    Dim sCount As Long
    Dim LookSub As Long
    Dim sID As Long
    Dim sString As String
    
    TheWindow = notepad
    aMenu& = GetMenu(TheWindow)
    mCount& = GetMenuItemCount(aMenu&)
    For LookFor& = 0& To mCount& - 1
        sMenu& = GetSubMenu(aMenu&, LookFor&)
        sCount& = GetMenuItemCount(sMenu&)
        For LookSub& = 0 To sCount& - 1
            sID& = GetMenuItemID(sMenu&, LookSub&)
            sString$ = String$ (100 , " ")
            Call GetMenuString(sMenu&, sID&, sString$, 100&, 1&)
            If InStr(LCase(sString$), LCase("Templates and Add-&Ins…")) Then
                Call SendMessageLong(TheWindow, WM_COMMAND, sID&, 0&)
                Exit Sub
            End If
        Next LookSub&
    Next LookFor&
    End Sub
    don't know the class of word, you must find that out before above code will work!!!!
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The class name for Word is OpusApp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width