dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] Run MS Office

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    101

    Resolved [RESOLVED] Run MS Office

    Hi dears
    I have this code to run MS Word and other office apps, I have MS office 2007 and Office 2010 on my Laptop, but office is not installed on my PC.
    I want to ask user "which version of office do you want to run? choose" Or show message "MS Office not found!"
    How
    When I click command "MSRun_Click()" detect ms word version and choose one to run, and ms word exist or not?
    Sorry for my bad English language!
    Code:
    Option Explicit
    
    Private Declare Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" ( _
        ByVal hwnd As Long, _
        ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" ( _
        ByVal hwnd As Long, _
        ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As Long
    Private Declare Function SetLayeredWindowAttributes Lib "user32" ( _
        ByVal hwnd As Long, _
        ByVal crKey As Long, _
        ByVal bAlpha As Byte, _
        ByVal dwFlags As Long) As Long
    Private Const GWL_EXSTYLE = (-20)
    Private Const WS_EX_LAYERED = &H80000
    Private Const LWA_COLORKEY = &H1&
    Private Const LWA_ALPHA = &H2&
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    Const SW_HIDE = 0
    Const SW_SHOWNORMAL = 1
    Const SW_NORMAL = 1
    Const SW_SHOWMINIMIZED = 2
    Const SW_SHOWMAXIMIZED = 3
    Const SW_MAXIMIZE = 3
    Const SW_SHOWNOACTIVATE = 4
    Const SW_SHOW = 5
    Const SW_MINIMIZE = 6
    Const SW_SHOWMINNOACTIVE = 7
    Const SW_SHOWNA = 8
    Const SW_RESTORE = 9
    Const SW_SHOWDEFAULT = 10
    Const SW_MAX = 10
    
    
    Private Sub MSRun_Click()
    ShellExecute 0&, vbNullString, "winword", vbNullString, vbNullString, SW_SHOWDEFAULT
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,557

    Re: Run MS Office

    you would need to search the registry to find which versions of office are installed
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    101

    Re: Run MS Office

    Quote Originally Posted by westconn1 View Post
    you would need to search the registry to find which versions of office are installed
    menuTest.zip

    This is my project.
    How can I switch between Office 2007 and 2010
    And
    How can I check Office is installed and detect its version?

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,609

    Re: Run MS Office

    Why do you want to know which version of Office is installed and what's the purpose of having multiple Office versions on a single PC?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    101

    Re: Run MS Office

    Quote Originally Posted by Arnoutdv View Post
    Why do you want to know which version of Office is installed and what's the purpose of having multiple Office versions on a single PC?
    Nice question!
    Because I know which version of Office is on my machine, and my project perfectly work! But I don't know other users machine (which version is installed)
    I had same project, it worked only on MS Office 32bit, Now I changed my Office to MS Office 64bit, no-more work. therefore I want a project to resolve this problem. I can't change my Apps, I want something flexible . . .
    I will be happy with your help!

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,609

    Re: Run MS Office

    Quote Originally Posted by Arnoutdv
    According to me Office automation from VB6 with Office 64 bit won't work.
    I'm actually not sure whether this is true, I don't have access to 64 bit versions of Office to test it myself.

    So I don't know what you want to do if you encounter a 64bit installation of MS Office

    To check whether an application is 64 bit you can use the GetBinaryType() API:
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    Last edited by Arnoutdv; Jul 3rd, 2017 at 08:11 AM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    101

    Re: Run MS Office

    Quote Originally Posted by Arnoutdv View Post
    According to Office automation from VB6 with Office 64 bit won't work.
    So I don't know what you want to do if you encounter a 64bit installation of MS Office

    To check whether an application is 64 bit you can use the GetBinaryType() API:
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    Ok forget 32bit and 64bit
    how can I detect Offices, Is installed office 2007 or 2010 or else?
    my office is 2010 but I have 2007 on my PC ! How to resolve this problem?
    how this project run on both machines?
    And maybe my friends machine hasn't office!
    If you understand and If you don't mind help me.
    Thank you for your replies

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,609

    Re: Run MS Office

    If there is no Office installed then you are out of luck.
    Normally for Office automation for most methods it doesn't matter which version of Office is installed.

    My application uses some Excel automation for creating a pivot table, uses late bounding and is used by many clients with Office version from 2003 up to 2016.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    101

    Re: Run MS Office

    Quote Originally Posted by Arnoutdv View Post
    If there is no Office installed then you are out of luck.
    Normally for Office automation for most methods it doesn't matter which version of Office is installed.

    My application uses some Excel automation for creating a pivot table, uses late bounding and is used by many clients with Office version from 2003 up to 2016.
    Ok! Thank you

    Sincerely
    Mahmood Khaleel Pirani

  10. #10
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,697

    Re: [RESOLVED] Run MS Office

    If you are only using common functions, properties and methods to all office versions then it "may" be safe to just test if office is installed or not.
    However if you need to determine which is installed you can use late binding and if creation of the application object is successful then it will be installed and you can get the version of what is there.

    See second code example in the first post
    http://www.vbforums.com/showthread.p...-an-Office-App
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width