Dialog Boxes

R

Renee Voice

Dear All

I am new to Word VBA and am struggling. I hope someone can help me.

I need to bring up the file,open dialog box so that I can get the user to
insert the name of a picture that they need to insert. I want them to be
able to move between folders to select the file they need. This must then be
stored to that they can insert the picture (logo) in a text box.

I have looked at the dialogs(wddialogfileopen). display and I can get it to
store the name of the file but I can't find out how to store the location.

I would very much appreciate it if someone can help. I have to get this
done as soon as possible.

Thanks again.
Renee
 
J

Jezebel

If you're browsing for a file, the CommonDialog control is easier to use
than the FileOpen dialog.

You'll need to explain what you mean by 'stored' -- for the session? from
one Word session to another? from one document to another?
 
D

Doug Robbins - Word MVP

Here's the way I do that:

' Display the InsertPicture dialog
With Dialogs(wdDialogInsertPicture)
If .Display Then
'Populate the txtLargeLogoPath control with the selected
filename
txtLargeLogoPath = WordBasic.FilenameInfo$(.Name, 1)
cmdInsertInfoPlusLogos.Enabled = True
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Renee Voice

Dear Doug

Thanks so much for your help - it was great. It works well.

Do you know much about Word and Access automation. I am calling Word from
Access through Createobject - it all works well but because I have a mail
merge which is opening the datasourse (the access database itself) it won't
let me run the process again unless I close both Access and Word. I have set
the application to nothing and I have tired quitting to no avail. What I
could do possibly is to change the source of the data somehow - insert it
into a word table or something.

Any ideas - much appreciated.

Once again thank you so much.

Regards
Renee
 
D

Doug Robbins - Word MVP

Would need to see your code.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Renee Voice

Dear Doug

Here is the code:

Dim wrdapp As Object

Set wrdapp = CreateObject("word.application")
wrdapp.Visible = True
wrdapp.Documents.Add Template:=strTemplate, NewTemplate:=False,
DocumentType:=0
wrdapp.Selection.GoTo What:=wdGoToBookmark, Name:="logo"
wrdapp.ScreenUpdating = False
With wrdapp.Dialogs(wdDialogInsertPicture)
If .Display Then
txtLargeLogoPath = wrdapp.WordBasic.FileNameInfo$(.Name, 1)
End If
End With
wrdapp.Selection.InlineShapes.AddPicture FileName:=txtLargeLogoPath,
LinkToFile _
:=False, SaveWithDocument:=True
wrdapp.Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
wrdapp.Selection.InlineShapes(1).Height = 22.7
wrdapp.Selection.InlineShapes(1).Width = 126.15
wrdapp.ActiveDocument.MailMerge.OpenDataSource Name:= _
strDbaseName, ConfirmConversions:=False, ReadOnly:=False _
, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:= _
"", Revert:=False, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
Source=C:\User\Submission Tool.mdb;Mode=Read;Extended Properties="""";Jet
OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database
Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Da" _
, SQLStatement:="SELECT * FROM `tblData`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
With wrdapp.Selection
.GoTo What:=wdGoToBookmark, Name:="Cover"
.InsertFile FileName:=strSubDoc, Range:=strBkMarkNme
.GoTo What:=wdGoToBookmark, Name:="Def"
ActiveDocument.AttachedTemplate.AutoTextEntries(strDefNme).Insert Where _
:=Selection.Range
'.........
End With
wrdapp.ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
wrdapp.ScreenUpdating = True
Set wrdapp = Nothing


Thanks so much for your time. I really admire the people who help so much
in these groups. I struggle so much time wise that I appreciate the time you
give us.
Regards
Renee
 
D

Doug Robbins - Word MVP

Did you omit some code where the '......... appears in the following:

ActiveDocument.AttachedTemplate.AutoTextEntries(strDefNme).Insert Where _
:=Selection.Range
'.........
End With

You do not seem to be closing the document and as a result of setting the
wrdapp to nothing without doing so, you are probably leaving a 'lockfile' in
place that is causing the behaviour that you are experiencing.

Aside from that, you should really declare an object for the document using

Dim wrdDoc as Document

then use

Set wrdDoc = wrdapp.Documents.Add Template:=strTemplate, NewTemplate:=False,
DocumentType:=0

and then use

wrdDoc.Selection.GoTo What:=wdGoToBookmark, Name:="logo"

instead of the commands such as

wrdapp.Selection.GoTo What:=wdGoToBookmark, Name:="logo"

But, I would try and use the .Range object rather than moving the Selection
around.

When you have finished with the document, you should then use:

wrdDoc.Close wdDoNotSaveChanges

if you do not need to save changes to the document, or use

wrdDoc.SaveAs

giving a file name and then use

wrdDoc.Close

Then when you set wrdApp to nothing, there should be nothing left around.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Renee Voice

Thanks Doug for the prompt response.

There is code in between - there is a lot of going to bookmarks and then
iserting autotexts so I lef them out.

The problem is that the document has to be open. They are using Access as
an input feature and are using selections in Access to insert different texts
in different parts of the document. The main point is to view the document
at the end.

I have tried to add the code
Set wrdDoc = wrdapp.Documents.Add Template:=strTemplate, NewTemplate:=False,
DocumentType:=0
as you suggested but I keep getting an error:
Compile error expected end of sentence

Once again thanks for the help.

Regards
Renee
 
R

Renee Voice

Hi Doug Me again

I tried your suggestion without declaring the document variable but closing
the document, quitting and then setting wrdapp to nothing and I still am
unable to run the code again without closing both Access and Word. Any ideas>

Sorry to bother you.

Thanks
Renee
 
D

Doug Robbins - Word MVP

Just use

Set wrdDoc = wrdapp.Documents.Add Template:=strTemplate

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Renee Voice

Thanks Doug will try that.

--
Renee Voice


Doug Robbins - Word MVP said:
Just use

Set wrdDoc = wrdapp.Documents.Add Template:=strTemplate

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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