Welcome Guest ( Log In | Click here to Register a free account now! )
Welcome to Bleeping Computer, 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.![]() ![]() |
Jun 14 2009, 08:08 PM
Post
#1
|
|
![]() Member ![]() ![]() Group: Members Posts: 93 Joined: 7-August 05 From: NYC Member No.: 30,278 |
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 |
|
|
|
Jun 17 2009, 07:30 AM
Post
#2
|
|
|
Senior Member ![]() ![]() ![]() ![]() Group: Members Posts: 535 Joined: 25-January 07 Member No.: 108,272 |
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? -------------------- Keith
http://www.martin2k.co.uk/forums I've been programming with VB for 13 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning. |
|
|
|
Jun 17 2009, 03:28 PM
Post
#3
|
|
![]() Member ![]() ![]() Group: Members Posts: 93 Joined: 7-August 05 From: NYC Member No.: 30,278 |
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 |
|
|
|
Jun 18 2009, 06:14 AM
Post
#4
|
|
|
Senior Member ![]() ![]() ![]() ![]() Group: Members Posts: 535 Joined: 25-January 07 Member No.: 108,272 |
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. 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. -------------------- Keith
http://www.martin2k.co.uk/forums I've been programming with VB for 13 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning. |
|
|
|
Jun 18 2009, 05:10 PM
Post
#5
|
|
![]() Member ![]() ![]() Group: Members Posts: 93 Joined: 7-August 05 From: NYC Member No.: 30,278 |
Hi keith,
Thanks for the cudos on the right VB 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 |
|
|
|
Jun 24 2009, 05:09 AM
Post
#6
|
|
|
Forum Addict ![]() ![]() ![]() ![]() ![]() ![]() Group: BC Advisor Posts: 1,367 Joined: 6-July 08 From: South Garden Member No.: 220,807 |
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 -------------------- |
|
|
|
Jun 25 2009, 04:24 PM
Post
#7
|
|
|
Member ![]() ![]() Group: Members Posts: 28 Joined: 20-February 09 From: MI Member No.: 298,494 |
try this i
but it requires Excel to be Installed CODE sub whatever_the_Combobox_event_is(events in here) ' the file that has been selected in the ComboBox 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 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! This post has been edited by chx101: Jun 25 2009, 04:25 PM -------------------- CHX101
|
|
|
|
Jul 1 2009, 10:33 PM
Post
#8
|
|
![]() Member ![]() ![]() Group: Members Posts: 93 Joined: 7-August 05 From: NYC Member No.: 30,278 |
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 |
|
|
|
Jul 1 2009, 11:03 PM
Post
#9
|
|
|
Forum Addict ![]() ![]() ![]() ![]() ![]() ![]() Group: BC Advisor Posts: 1,367 Joined: 6-July 08 From: South Garden Member No.: 220,807 |
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. -------------------- |
|
|
|
Jul 2 2009, 10:18 PM
Post
#10
|
|
![]() Member ![]() ![]() Group: Members Posts: 93 Joined: 7-August 05 From: NYC Member No.: 30,278 |
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 |
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 8th November 2009 - 11:35 AM |