control open data source dialog box with vba

M

Mikel

Is there any way using VBA to set the file type to select
the *.txt for the Open Data Source Dialog box. I have
been able to do this with the File Open and File Save As
Dialog boxes but can't seem to get it to work with the
Open Data Source one. I am running windows 2000 and Word
97 and 2000. I sent this to the mail merge group last
week. Perhaps that was the incorrect group as I haven't
heard anything back yet, so I am trying this one. If this
is the wrong group please guide me to the correct one.

Thanks in advance,
Mikel
 
J

Jezebel

Why not just use the Common Dialog to get the filename, then execute the
Data Source with that name as argument?
 
M

Mikel

Thank you for responding...
I am very new with programming and word automation. Please
bear with me. Could you be a little me specific on the use
of the Common Dialog you refer to. Is there anywhere you
can point me to to study up on this stuff. I will look at
my books. Thanks again
 
J

Jezebel

Create a UserForm and put a CommonDialog control on it, then write code to
display the control. It's reasonably well explained, with examples, in the
VBA help files.
 
M

Mikel

I have take the advise given earlier and created a
UserForm with a list box control. What I am trying to do
is populate the list box with the contents of a directory.
I have spent quite a few days in the WORD VBA help files
but the light just hasn't clicked on. I can get the
contents of the directory to print to the immediate window
but don't know how to capture the contents and pass it to
the UserForm. The code I am using to get the directory
contents is below.

Thank you for all your help. Learning new things can be
very frustrating at times but also very rewarding. I see
how powerfull word automation can be but the details are
quite overwhelming.

Mikel


Public Sub ReadNewJobDirectory()

Dim myFile As String
Dim Counter As Long



'create a dynamic array variable, and then declare it's
initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(100)

'Loop through all the files in the Directory by using Dir$
function
myFile = Dir$("c:\New Job\*.txt")
Do While myFile <> ""
DirectoryListArray(Counter) = myFile
myFile = Dir$
Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by
using Redim Preserve
ReDim Preserve DirectoryListArray(Counter - 1)

For Counter = 0 To UBound(DirectoryListArray)
Debug.Print 'writes the results to the immediate window
(press Ctrl + G to view it)
Debug.Print DirectoryListArray(Counter)
Next Counter

'To populate a ListBox from the array you could use:
ListBox1.List = DirectoryListArray


End Sub
 
D

Doug Robbins - Word MVP

The following modification of the code in the article "Insert into a
document the names of all files in a selected folder" at:

http://word.mvps.org/FAQs/MacrosVBA/InsertFileNames.htm

will load the contents of the selected folder into ListBox1

Dim MyPath As String
Dim MyName As String

'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
ListBox1.AddItem MyName
MyName = Dir
Loop

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
M

Mikel

Works great!!!
Thank you very much,
Mikel
-----Original Message-----
The following modification of the code in the article "Insert into a
document the names of all files in a selected folder" at:

http://word.mvps.org/FAQs/MacrosVBA/InsertFileNames.htm

will load the contents of the selected folder into ListBox1

Dim MyPath As String
Dim MyName As String

'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
ListBox1.AddItem MyName
MyName = Dir
Loop

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP


.
 
S

Stumped

I am hoping maybe you might be able to help with a similar issue.
I am not able to use the Common Dialog control because the way my users are set up the control is not "licensed" (even though it is).
We have done the MS http://support.microsoft.com/?kbid=312594 to get the users licsensed. But it is not working even though they are technically licensed. The BEST solution is to use the comdlg32.dll. However even with the API books and Internet I can't find a straight forward example of how to apply the code to create the "OpenFile" and "SaveFile" methods using the "GetOpenFileName" function. The best example I found was in German. I need something I can put into a module and step through to throughly understand. Any help would be appreciated.
Thank you.
 
D

Doug Robbins - Word MVP

I don't see much similarity between this and the original question and
unfortunately, I don't know the answer to your question.

I would suggest that you start a new thread as a question that gets tacked
onto the end of another thread can very easily be overlooked by others who
may be able to help you.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Stumped said:
I am hoping maybe you might be able to help with a similar issue.
I am not able to use the Common Dialog control because the way my users
are set up the control is not "licensed" (even though it is).
users licsensed. But it is not working even though they are technically
licensed. The BEST solution is to use the comdlg32.dll. However even with
the API books and Internet I can't find a straight forward example of how to
apply the code to create the "OpenFile" and "SaveFile" methods using the
"GetOpenFileName" function. The best example I found was in German. I need
something I can put into a module and step through to throughly understand.
Any help would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top