Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
EXCEL USERFORM
Gary
Here's a sub in the Initialize event that will find all the jpg's in a folder and list them on your userform. Private Sub UserForm_Initialize() Dim Fldr As String Dim FName As String Dim i As Long Dim cnt As Control Fldr = "C:\My Documents\My Pictures\" FName = Dir(Fldr & "*.jpg") i = 10 Do While Len(FName) 0 Set cnt = Me.Controls.Add("forms.checkbox.1", , True) cnt.Top = i cnt.Left = 10 Set cnt = Me.Controls.Add("forms.label.1", , True) cnt.Top = i cnt.Left = 30 cnt.Caption = FName i = i + 30 FName = Dir Loop End Sub -- Dick Kusleika MVP - Excel www.dicks-clicks.com Post all replies to the newsgroup. "Gary Burke" wrote in message ... Hi there, Have a desire/need to populate a userform (continuous form ??) with a list of files from a folder (of a selected type only - pictures), and provide the facility to search other folders, so am guessing that i would list the selected files(of a given type) and folders. I know I could use the interface to windows, to activate the windows "Open File" dialogue box, but dont to do that. I would also like to have on the form, a check box, against each file listed, so the user may "select" the file they wish to use. Propose adding an "execute" button, to do something with the file once selected. This will be to insert the picture into a designated area on the excel worksheet, and to resize it. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
EXCEL USERFORM
That code works great, Dick. The only problem is if you have more than
a few .jpg's, you can't see them. My suggestion is to put a frame on this form and then put the following code into the Enter event of the frame: Private Sub Frame1_Enter() Dim Fldr As String Dim FName As String Dim i As Long Dim cnt As Control Fldr = "C:\documents and settings\markbi\My Documents\My Pictures\" FName = Dir(Fldr & "*.jpg") i = 10 Do While Len(FName) 0 Set cnt = Me.Frame1.Controls.Add("forms.checkbox.1", , True) cnt.Top = i cnt.Left = 10 Set cnt = Me.Frame1.Controls.Add("forms.label.1", , True) cnt.Top = i cnt.Left = 30 cnt.Caption = FName i = i + 30 FName = Dir Loop Me.Frame1.ScrollHeight = i End Sub Again, just a slight improvement to already great code! Mark --- Mark Bigelow mjbigelow at hotmail dot com http://hm.imperialoiltx.com *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
EXCEL USERFORM
Thanks guys, that works great. However, would like to expand the code now to do 2 things. 1. List folders, so that the user can change the active folder, and refresh the list of files. 2. Allow the user to do something with the selected file/folder. What code would i use, to say insert the selected file at a given location (ie how do i reference the selected file), and what code would I use to change the folder, if the user selected a folder instead of a file ? Maybe the checkbox concept was the wrong way, or maybe there is a better way ??? Thanks in advance. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
EXCEL USERFORM
Gary
You should consider using the GetOpenFileName method instead of trying to program all this stuff yourself. It won't give you quite the interface you're looking for, but it will save you hours of programming. Check it out in help. -- Dick Kusleika MVP - Excel www.dicks-clicks.com Post all replies to the newsgroup. "Gary Burke" wrote in message ... Thanks guys, that works great. However, would like to expand the code now to do 2 things. 1. List folders, so that the user can change the active folder, and refresh the list of files. 2. Allow the user to do something with the selected file/folder. What code would i use, to say insert the selected file at a given location (ie how do i reference the selected file), and what code would I use to change the folder, if the user selected a folder instead of a file ? Maybe the checkbox concept was the wrong way, or maybe there is a better way ??? Thanks in advance. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Automatic Userform Excel 2003 | Excel Discussion (Misc queries) | |||
VBA with userform in excel | Excel Discussion (Misc queries) | |||
display status bar value in excel userform? | Excel Discussion (Misc queries) | |||
Userform in excel | Excel Discussion (Misc queries) |