Results 1 to 3 of 3

Thread: Combobox issue

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2015
    Posts
    4

    Combobox issue

    i am trying to get a Drop-down Combo-box to open an excel file, just can't seen to get it to work, what do i need in the button1 Click to make my selected Excel file open..

    thanks for any help

    <Code>

    Option Explicit
    'do declare these variables you need to add a reference
    'to the microsoft excel 'xx' object library.


    Dim xl As New Excel.Application
    Dim xlsheet As Excel.Worksheet
    Dim xlwbook As Excel.Workbook

    Private Sub Combo_Change()
    'don 't forget to do this or you'll not be able to open
    'book1.xls again, untill you restart you pc.

    xl.close

    End Sub

    Private Sub Command_Click(Index As Integer)
    End

    End Sub

    Private Sub Command1_Click(Index As Integer)

    Dim Combo As Combobox

    Dim xl As New Excel.Application
    Dim xlsheet As Excel.Worksheet
    Dim xlwbook As Excel.Workbook

    'Close excel or reboot PC
    xl.Quit

    Set xl = CreateObject("Excel.Application")

    xl.Visible = True

    Set xlwbook = xl.Workbooks.Open ' value Selected in Combo should open "need help here"





    'strSelect = ComboBox1.Value
    'Workbooks.Open FileName:=strSelect

    End Sub

    Private Sub Form_Load()

    'Files in folder listed in Listbox1
    Dim FSO As Object, fld As Object, Fil As Object
    Dim SubFolderName As String
    Dim i As Integer
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Me.Combo.Clear 'clear previous entries
    SubFolderName = "C:\REPORTS"
    Set fld = FSO.GetFolder(SubFolderName)
    For Each Fil In fld.Files
    i = i + 1
    Me.Combo.AddItem Fil.Name

    Next Fil

    '----------------------------- ListBox Filling Content from a directory--------------------------------------
    'Files in folder listed in Listbox1
    ' Dim FSO As Object, fld As Object, Fil As Object
    ' Dim SubFolderName As String
    ' Dim i As Integer
    'Set FSO = CreateObject("Scripting.FileSystemObject")
    'Me.Listbox1.Clear 'clear previous entries
    'SubFolderName = "C:\"
    'Set fld = FSO.GetFolder(SubFolderName)
    'For Each Fil In fld.Files
    ' i = i + 1
    ' Me.Listbox1.AddItem Fil.Name

    'Next Fil


    End Sub

    </code>

  2. #2
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Combobox issue

    If all you want to do is open a workbook in excel and not manipulating the workbook from vb6 then all you need is the Shell() command.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  3. #3
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Combobox issue

    A fairly common 'gotcha'. Use the Click event vice Change.

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
  •  



Click Here to Expand Forum to Full Width