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 / February 2006

Tip: Looking for answers? Try searching our database.

Word form with VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MAB - 23 Feb 2006 17:15 GMT
I am designing a form with word and VBA.
I would like the user of the form to be able to drag and drop a jpg into the
form, which would them be copied into the word doc.
Jonathan West - 23 Feb 2006 20:16 GMT
>I am designing a form with word and VBA.
> I would like the user of the form to be able to drag and drop a jpg into
> the
> form, which would them be copied into the word doc.

Drag & drop might be rather difficult. But you could have a Browse button on
your UserForm, which could display a dialog using the FileDialog object.

Once you have the filename of the jpg, you can assign it to an Image object
on the Userform, and in due course insert it into the document by using the
Shapes.Add method or InlineShapes.Add method.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

MAB - 24 Feb 2006 17:01 GMT
Do you mean a "browse" botton so I could attach it to the word doc as a
result?
because that could work, just not sure how to do it.

> >I am designing a form with word and VBA.
> > I would like the user of the form to be able to drag and drop a jpg into
[quoted text clipped - 7 lines]
> on the Userform, and in due course insert it into the document by using the
> Shapes.Add method or InlineShapes.Add method.
Jonathan West - 24 Feb 2006 17:31 GMT
I got the impression that your "form" and your "word doc" were two separate
things, and was assuming that you were therefore using a UserForm (custom
dialog)

Based on what you have now said, I'm no longer sure that is the case. Could
you describe in a bit more detail what you are doing overall?

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Do you mean a "browse" botton so I could attach it to the word doc as a
> result?
[quoted text clipped - 15 lines]
>> the
>> Shapes.Add method or InlineShapes.Add method.
MAB - 24 Feb 2006 18:35 GMT
A user would open up a word templete  (.dot) file. The form embedded into the
.dot file would prompt the user to fill out some fields, including one to
attach a jpg/gif/bmp  into the form which would then be imported into the dot
file along with the answers to the other fields
Doug Robbins - Word MVP - 24 Feb 2006 19:11 GMT
For this you should be using a userform of the type discussed in the article
"How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

Then you need a button on the form with a caption something like "Browse for
Image" and for the Click() event for that form, you would use the following
code:

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

In the form from which I grabbed this piece of code, the user was browsing
for a file that contained and organization chart and there was a textbox
(txtOrgChartPath) on the form that was populated with the path and filename
of the file that was selected by the user when the InsertPicture dialog was
displayed.  The code also activated a button that when clicked, inserted the
organisation chart into the document using the following code:

Private Sub cmdInsertOrgChart_Click()
'   Check that a file has been selected
   If InStr(txtOrgChartPath, ":") = 0 Then
       MsgBox "You must select a file for the Organization Chart."
       Exit Sub
   End If
'Insert organization chart into Quality Manual
   Set myDoc = Documents.Open(PathofSystemFiles & "\Quality
Manual\Quality_Manual.doc")
   If myDoc.Bookmarks.Exists("Org_Chart") = True Then
'Clear existing organization chart
       myDoc.Bookmarks("Org_Chart").Range.Tables(1).Cell(1, 2).Range.Delete
'Insert new organization chart
       myDoc.Bookmarks("Org_Chart").Range.Tables(1).Cell(1,
2).Range.InlineShapes.AddPicture Filename:=txtOrgChartPath
'Save and close the document
       myDoc.Save
   End If
   myDoc.Close

End Sub

You will need to modify this for your situation, but it should show you the
necessary syntax to use.

Signature

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

>A user would open up a word templete  (.dot) file. The form embedded into
>the
> .dot file would prompt the user to fill out some fields, including one to
> attach a jpg/gif/bmp  into the form which would then be imported into the
> dot
> file along with the answers to the other fields
Jonathan West - 25 Feb 2006 11:47 GMT
>A user would open up a word templete  (.dot) file. The form embedded into
>the
> .dot file would prompt the user to fill out some fields, including one to
> attach a jpg/gif/bmp  into the form which would then be imported into the
> dot
> file along with the answers to the other fields

Doug's approach is one way. Another is to include a MACROBUTTON field in the
document, like this

{ MACROBUTTON BrowseForPicture Double-click to insert a picture}, where the
{ } characters are field braces inserted by pressing Ctrl-F9.

Then the BrowseForPicture macro can display the Insert Picture dialog using
code based on what Doug has provided. To insert the picture into the
document, you may need to have the code temporarily unprotect the document,
insert the picture, and then re-protect the document.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Rate this thread:






 
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.