Results 1 to 10 of 10

Thread: Open an existing *.xls file

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Location
    Luleå
    Posts
    11

    Open an existing *.xls file

    Hi

    I want to be able to open an existing xls-file to read by pressing a button.

    Somebody help me, please!!!

    "First timer"
    WW

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You want to open an Excel file using a program you are writting in VB or Excel's VBA?
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Location
    Luleå
    Posts
    11
    VB
    WW

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    In VB click on Project > References and select "MS Excel x.x Object Library"
    Here is some code to get you started.
    Need 1 command button, 1 form, 1 textbox.
    VB Code:
    1. Option Explicit
    2.  
    3. Private moXl As Excel.Application
    4.  
    5. Private Sub Form_Load()
    6.     Set moXl = New Excel.Application
    7. End Sub
    8.  
    9. Private Sub Command1_Click()
    10.  
    11.     On Error GoTo No_Bugs
    12.    
    13.     moXl.Workbooks.Open Text1.Text, , False
    14.     moXl.Visible = True
    15.     moXl.WindowState = xlMaximized
    16.     moXl.Application.DisplayAlerts = True ' PROMPT USER TO SAVE UPON EXIT OF EXCELL
    17.     Exit Sub
    18.    
    19. No_Bugs:
    20.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation
    21. End Sub
    22.  
    23. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    24.     Set moXl = Nothing
    25. End Sub
    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Location
    Luleå
    Posts
    11

    Thumbs up

    Thanks! That was great ... and I see now what a ****ty problem there really was!

    Though I do have another question

    I allso need to be able to open a *.pdf-file


    WW

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    If the workstation has Acrobat Reader then just shell the pdf out.
    It will open with the default app for the .pdf extension.
    VB Code:
    1. Private Sub Command2_Click()
    2.     If Text2.Text <> "" Then
    3.         Shell Text2.Text, vbMaximizedFocus
    4.     End If
    5. End Sub
    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Location
    Luleå
    Posts
    11
    Still is'nt working!

    Could it be because of an referens that is'nt activated?



    This is the code

    Private Sub Command12_Click()

    'The pathname in Text12.text is "C:\Documents and Settings\FRAT\Desktop\merit_pdf.pdf"

    If Text12.Text <> "" Then
    Shell Text12.Text, vbMaximizedFocus
    End If

    End Sub
    WW

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Sorry about that, I forgot to tell you to include the path to Acrobat.
    This is my path to Acrobat and pass the parameter of the filename to open.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.     Dim sFile As String
    6.    
    7.     sFile = Text1.Text
    8.     Shell "D:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe " & sFile, vbMaximizedFocus
    9.    
    10. End Sub
    Last edited by RobDog888; Mar 31st, 2004 at 11:11 AM.
    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Location
    Luleå
    Posts
    11

    Wink

    Thanks!

    Now everything's perfect!


    WW

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Gald to help.
    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

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