Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Visual Basic


  • Please log in to reply
9 replies to this topic

#1 looney2340

looney2340

  • Members
  • 202 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NYC
  • Local time:07:39 AM

Posted 14 June 2009 - 08:08 PM

Hi everyone,

Im writting a program and i have a combo box on a form that is populated from a text file and it works. Can anyone help me with the code on when i click on a name in the combo box i need it to open an excel form associated with that particular name. The list will contain approx 100 names and each one will have its own excel form. I have been searching and can not find anything anywhere to help me.

Thanks

BC AdBot (Login to Remove)

 


m

#2 Keithuk

Keithuk

  • Members
  • 951 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:39 PM

Posted 17 June 2009 - 07:30 AM

Im writting a program and i have a combo box on a form that is populated from a text file and it works. Can anyone help me with the code on when i click on a name in the combo box i need it to open an excel form associated with that particular name. The list will contain approx 100 names and each one will have its own excel form. I have been searching and can not find anything anywhere to help me.


First off it will depend on which VB you are using VB6 or VB.Net?

A ComboBox with filenames in will only work in the App.Path unless you show the location if the file its somewhere else.

If you're only showing filenames in the ComboBox then why don't you just use the CommonDialogl control or ComDlg32.dll API calls to find an Excel file? :thumbsup:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#3 looney2340

looney2340
  • Topic Starter

  • Members
  • 202 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NYC
  • Local time:07:39 AM

Posted 17 June 2009 - 03:28 PM

Hi Keith,

Thanks for the reply i am writting this for a friend to use with her busniess.....i havent used vb in such a long time so im starting almost from the beginning.......i am using VB6 Enterprise edition i am not showing the file names of the specific excel file in the combo box only names of people from a text file and when i click on it i need an excel file to open that is associated with it as of now im not sure what the names of the excel files would be so i just made one to test the program with.....if that make sense LoL....i have never used API calls but have been doing some reading about it.
Isnt there a way to use .....list.index so when i click on a name in the list i can get it to open the needed file ?

I hope i dont sound to much like a beginner just finding my way back into VB.

Thanks for the help

#4 Keithuk

Keithuk

  • Members
  • 951 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:39 PM

Posted 18 June 2009 - 06:14 AM

i am using VB6 Enterprise edition i am not showing the file names of the specific excel file in the combo box only names of people from a text file and when i click on it i need an excel file to open that is associated with it as of now im not sure what the names of the excel files would be so i just made one to test the program with.....if that make sense LoL....i have never used API calls but have been doing some reading about it.
Isnt there a way to use .....list.index so when i click on a name in the list i can get it to open the needed file ?


Ok I see you're using proper VB, good job. :thumbsup:

So this text file will have names in that you can select from the ComboBox and it will open an Excel file and show that name in a particular cell and any more info thats needed?

Now depending on how you do this you may need Excel installed on the computer you are running your app from. Or you can just reference it. :flowers:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#5 looney2340

looney2340
  • Topic Starter

  • Members
  • 202 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NYC
  • Local time:07:39 AM

Posted 18 June 2009 - 05:10 PM

Hi keith,

Thanks for the cudos on the right VB :thumbsup:

Yes the combo box is populated with names from a txt file but i dont need the name chosen in the combo box to be added into a cell in an excel file.....what i need is an excel file that already has info in it to open...and the computer the app will be on does have excel on it here is the code i will use to open excel i have it already in a command button for something else ..


Dim oXLApp As Excel.Application
Dim oxlbook As Excel.Workbook
Set oXLApp = New Excel.Application
Set oxlbook = oXLApp.Workbooks.Open("C:\Users\Henry\Desktop\FILENAME.xls") <~~~~~THIS WOULD BE THE PATH OF THE FILE I WOULD NEED OPENED
oXLApp.Visible = True

Set oxlbook = Nothing
Set oXLApp = Nothing
End Sub

My problem is when i click on a name in the combo list i dont know how to code it so it opens the appropiate file i was trying the click event of the combo box but it opens the same file no matter where i click or what name because its the click event i hope im explaining what i need the right way. Im hope im not confusing you in what i need. LoL

The common dialog box is ok but im trying to make easier for my friend so all she has to do is click a patients name in a list and the file she needs opens for her....she needs it as simple as possible i was also thinking either a check box and command button or option button when chosen automatically opens the file needed but that would involve at least 100 buttons which i can code ok but would be a bit time consuming.

Thanks for the patience

#6 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:07:39 AM

Posted 24 June 2009 - 05:09 AM

If the computer has MS Excel installed, then simply use ShellExecute() to launch the respective excel file.
Something like this:
ShellExecute(Me.hwnd, "open","c:\myfile\demo.xls", "", "", 1)

More information on vbAccelerator:
http://www.vbaccelerator.com/codelib/shell/shellex.htm

#7 chx101

chx101

  • Members
  • 32 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:uSa
  • Local time:07:39 AM

Posted 25 June 2009 - 04:24 PM

try this i

but it requires Excel to be Installed

Dim FileN As New IO.FileInfo(ComboBox1.selectedItem) 'if there's an error add .ToString()

'check the file extension
Dim FileExt
Dim FileNameFull
FileNameFull = My.Computer.SystemFile.File(FileN).FullName
FileExt = My.Computer.SystemFile.File(FileN).Exstension

'if extension is Excel extension it will open the file as a new process, else error
if FileExt = ".xls" then

'Processe must have full path to its files, so
Process.Start(FileNameFull)

'we dont want an error so instead
Else If FileExt Is Not ".xls" then 'or use <> to replace Is Not

shell("Rundll32 Shell32.dll,OpenAs_ RunDLL " & FileNameFull,vbNormalFocus,false)

End if
_linenums:0'>sub whatever_the_Combobox_event_is(events in here)' the file that has been selected in the ComboBoxDim FileN As New IO.FileInfo(ComboBox1.selectedItem) 'if there's an error add .ToString()'check the file extensionDim FileExtDim FileNameFullFileNameFull = My.Computer.SystemFile.File(FileN).FullNameFileExt = My.Computer.SystemFile.File(FileN).Exstension'if extension is Excel extension it will open the file as a new process, else errorif FileExt = ".xls" then'Processe must have full path to its files, soProcess.Start(FileNameFull)'we dont want an error so insteadElse If FileExt Is Not ".xls" then 'or use <> to replace Is Notshell("Rundll32 Shell32.dll,OpenAs_ RunDLL " & FileNameFull,vbNormalFocus,false)End if




so what this does :
when you click select the file from the ComboBox it will check the file extension too see if its an excel sheet file extension
and if not it will bring up the Windows "Open With Dialog Box"

But Make Sure your ComboBox TextBox is Uneditable to avoid "file Not Found Error" and that the selected Item index is set to 0 to remove the Blank Space...You have to write this in the Form1_Load()

I think that will help, Good Luck!

Edited by chx101, 25 June 2009 - 04:25 PM.


#8 looney2340

looney2340
  • Topic Starter

  • Members
  • 202 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NYC
  • Local time:07:39 AM

Posted 01 July 2009 - 10:33 PM

Thank you Chx for the reply i have been away and just read your post i will give it a try and let you know how i make out

Thanks again

#9 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:07:39 AM

Posted 01 July 2009 - 11:03 PM

try this i

but it requires Excel to be Installed
......


If you read the whole topic you would find the person who asked the question is using VB6. The code you posted is in VB.NET. :thumbsup:

#10 looney2340

looney2340
  • Topic Starter

  • Members
  • 202 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NYC
  • Local time:07:39 AM

Posted 02 July 2009 - 10:18 PM

Hi romeo,

I was wondering why the code looked a little odd and couldnt get it to work properly...if anyone can help with a simple copy and past code it would be much appreciated....in the mean time ill keep plugging away with some new ideas on my own..

Thanks for the help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users