Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

help with common dialog for multiple file insert please

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
voip1234@mytrashmail.com - 23 Jan 2005 01:39 GMT
I wrote some code to let me select multiple files, then organize them
in
the order I want using listboxes and finally inserting.
For the common dialog stuff I used the code kindly
provided by Jonathan West on the following thread
http://groups-beta.google.com/group/microsoft.public.word.vba.customization/msg/
4f5145a2b1e13e12


Everything works according to the way it was designed to work.
Jonathan says
"If you select multiple files, the first entry in the listbox is the
folder
they were selected from, and the other entries are the names of the
selected
files. If a single file is selected, the full pathname is returned."

which is exactly what it does.
I would like it to behave the exact same way for one or multiple
files. Specifically I would like it to provide the path as the first
entry and the second as the file name even when only selecting
one file. I have looked at the common dialog code he wrote, but
cant figure out where this is an option if there actually is
one (i am new to vba). I was also told to parse the line when
it comes in as path and file name together, but I dont know how to
do this either.

I am guessing it has to be an option on the common dialog, and
I see a section that says
----------------
'put the members of the returned sFile
'string into an array. If multiselect,
'the first member is the path, and the
'remaining members are the files under
'that path selected.
ReDim vFileList(0)
iFileTotal = 0
Do While Len(buff) > 3
ReDim Preserve vFileList(iFileTotal)
vFileList(iFileTotal) = StripDelimitedItem(buff, vbNullChar)
iFileTotal = iFileTotal + 1
Loop

FileOpenDialog = vFileList
Else
FileOpenDialog = ""
End If

End Function

Private Function StripDelimitedItem(startStrg As String, _
delimiter As String) As String
----------------

which i guess is where the secret is....but can somebody
help me figure out what to change...i want path on first
entry and filename on the following listbox entries whether it was
multiselection or not.

thanks!!!!
Jezebel - 23 Jan 2005 02:53 GMT
There's no way to get it to do that if only one file is selected. The
multiple file approach is triggered a) by setting the Multiselect flag, and
b) by the user actually selecting multiple files. If they select only one
file, then the full path and name is the first and only segment of the
returned value.

> I wrote some code to let me select multiple files, then organize them
> in
> the order I want using listboxes and finally inserting.
> For the common dialog stuff I used the code kindly
> provided by Jonathan West on the following thread

http://groups-beta.google.com/group/microsoft.public.word.vba.customization/msg/
4f5145a2b1e13e12


> Everything works according to the way it was designed to work.
> Jonathan says
[quoted text clipped - 47 lines]
>
> thanks!!!!
voip1234@mytrashmail.com - 23 Jan 2005 08:46 GMT
thanks for the quick reply.
could you then please explain to me how one goes about "parsing" the
entry so that I can have the path on one variable and the filename on
another? I am guessing I should analyze the text from right to left
until the first '\' but I dont even know where to start to get it to do
that.
thanks!!
Jezebel - 23 Jan 2005 10:43 GMT
Path = left$(dlg.FileName, len(dlg.FileName) - len(dlg.FileTitle))

> thanks for the quick reply.
> could you then please explain to me how one goes about "parsing" the
[quoted text clipped - 3 lines]
> that.
> thanks!!
voip1234@mytrashmail.com - 23 Jan 2005 20:02 GMT
thanks again Jezebel, that is very helpful, I will try it inmediately.
Would you mind explaining how the command is working?
thanks again!!!!
Jezebel - 23 Jan 2005 20:55 GMT
FileName is the full name with path (if there is only one file selected).
FileTitle is the name without path.
So to get the path we want the left-hand segment of the FileName that
excludes the FileTitle. Len() is the length of a string. So if the FullName
is 40 characters, and the FileTitle is 10 characters, we want the left 30 of
FileName (or 29 if you don't want the trailing \).

.

> thanks again Jezebel, that is very helpful, I will try it inmediately.
> Would you mind explaining how the command is working?
> thanks again!!!!
voip1234@mytrashmail.com - 23 Jan 2005 22:55 GMT
thanks Jezebel...now I understand what its doing. I tried it but it
didnt work though.
After fiddling around with it and a few msgboxes to figure out what is
wrong
i found that the code to call the open dialog box defines the length of
the title and filename with a huge number of spaces, so when I do the
substraction, its a huge number minus a not so huge number which equals
the whole path and filename minus a few spaces....i.e. the resultant of
the path statement is the same as both path and filename.
I guess now I have to figure out how to strip off the spaces for the
Len statements to actually work.
thanks,
voip1234@mytrashmail.com - 23 Jan 2005 23:03 GMT
I just tried RTrim, LTrim, and Trim, but none of them helped....any
suggestions on what I can try next?
thank you.
Jezebel - 23 Jan 2005 23:35 GMT
Trim$() should certainly do it. If that's failing, I guess you have come
maverick characters getting in there. You can use ASC() to work out what.

> I just tried RTrim, LTrim, and Trim, but none of them helped....any
> suggestions on what I can try next?
> thank you.
voip1234@mytrashmail.com - 24 Jan 2005 02:40 GMT
once again you were right....it was Null chraracters that were
affecting the
behavior.
After a while of trying out to delete the characters using the few
commands I know,
i ended up doing a search and found the following code....which worked
-------------------
Private Function CTrim(s As String) As String
Dim l As Long
l = InStr(s, Chr$(0))
If l > 0 Then
CTrim = Left$(s, l - 1)
Else
CTrim = s
End If
End Function
--------------
thanks for all your help
Jezebel - 24 Jan 2005 02:47 GMT
You should invest a little time reading through the list of VBA functions.
Replace$() is the one you want for this --

NewString = Replace$(OldString, Chr$(0), "")

BTW, you might have noticed that these string functions can be used with or
without the dollar sign: Trim() or Trim$() etc. Without the dollar sign they
work on strings or variants; with the dollar sign they are string-specific,
which your code should be too, and are *much* faster.

> once again you were right....it was Null chraracters that were
> affecting the
[quoted text clipped - 14 lines]
> --------------
> thanks for all your help
voip1234@mytrashmail.com - 24 Jan 2005 03:56 GMT
i was about to ask about the $ and why some examples showed it with and
others without...but i decided not to as I had already asked a bunch of
questions....

about the replace command.....
i suppose that would work in my case but by adding an additional Trim
so it becomes something like
NewString = Trim$(Replace$(OldString, Chr$(0), ""))
as there are additional spaces in there after the null characters are
gone.
thanks for all your help
(back to work....now I have to figure out how to put the path on one
column in a listbox and the filename on another column)
voip1234@mytrashmail.com - 23 Jan 2005 10:23 GMT
thanks for the quick reply.
could you then please explain to me how one goes about "parsing" the
entry so that I can have the path on one variable and the filename on
another? I am guessing I should analyze the text from right to left
until the first '\' but I dont even know where to start to get it to do
that.
thanks!!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.