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 / March 2007

Tip: Looking for answers? Try searching our database.

VBA code to select a list of photos and then add them to a word doc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
danny - 28 Feb 2007 22:12 GMT
I would like to be able to select from a picture from a list of pictures and
then add that photo added to a open word document. The code listed below
will add the 2 pictures but i cannot choose only one to add. Can anyone
help.

thanks
danny

Sub Addpic()
'
'
Dim objShape

Set objShape = ActiveDocument.Shapes
objShape.AddPicture ("s:\pictures\Logos\aca.jpg")
objShape.AddPicture ("s:\pictures\Logos\HubZone.jpg")

End Sub
Karl E. Peterson - 28 Feb 2007 23:06 GMT
> I would like to be able to select from a picture from a list of pictures and
> then add that photo added to a open word document. The code listed below
[quoted text clipped - 14 lines]
>
> End Sub

How do you envision the user making the selection?  I mean, you could pop up
MsgBox's, one at a time, asking for both.  Or, you could pop up a UserForm, with a
more formal list.  The choices are really many.  Where do you see this going?
Signature

.NET: It's About Trust!
http://vfred.mvps.org

danny - 01 Mar 2007 13:38 GMT
Karl
I envision using either a userform or a listbox to select from.

Danny

>> I would like to be able to select from a picture from a list of pictures
>> and
[quoted text clipped - 20 lines]
> UserForm, with a more formal list.  The choices are really many.  Where do
> you see this going?
Karl E. Peterson - 01 Mar 2007 18:09 GMT
Have you ever created a userform?  Do you have any documents that contain userforms,
which you could inspect, to use as examples?  I guess what I"m asking is sort of a
classic usenet question -- what part of this problem are you having difficulty with?

> Karl
> I envision using either a userform or a listbox to select from.
[quoted text clipped - 28 lines]
>> .NET: It's About Trust!
>> http://vfred.mvps.org

Signature

.NET: It's About Trust!
http://vfred.mvps.org

danny - 01 Mar 2007 19:08 GMT
Karl
I created user forms in excel, but never in word.
danny

> Have you ever created a userform?  Do you have any documents that contain
> userforms, which you could inspect, to use as examples?  I guess what I"m
[quoted text clipped - 37 lines]
>>> .NET: It's About Trust!
>>> http://vfred.mvps.org
Karl E. Peterson - 01 Mar 2007 20:15 GMT
Same thing.  Do I need to repeat _my_ question?

> Karl
> I created user forms in excel, but never in word.
[quoted text clipped - 45 lines]
>> .NET: It's About Trust!
>> http://vfred.mvps.org

Signature

.NET: It's About Trust!
http://vfred.mvps.org

danny - 01 Mar 2007 21:30 GMT
Karl
I'm having trouble with the combo box code, listed below is the code i've
wrote
I have two pictures listed aca and hubzone. When i run the combo box it will
load the aca picture but it will not load the hubzone picture.

thanks
danny

Private Sub UserForm_Initialize()
With Me.ComboBox1
.AddItem "aca"
.AddItem "Hubzone"
'.ListIndex = 0
Dim aca
Dim Hubzone
Dim objShape
Set objShape = ActiveDocument.Shapes
If Me.ComboBox1 = aca Then
objShape.AddPicture ("s:\pictures\Logos\aca.jpg")
Else
objShape.AddPicture ("s:\pictures\Logos\HubZone.jpg")
End If
End With

End Sub

> Same thing.  Do I need to repeat _my_ question?
>
[quoted text clipped - 51 lines]
>>> .NET: It's About Trust!
>>> http://vfred.mvps.org
Karl E. Peterson - 01 Mar 2007 21:58 GMT
Hmmmm, usually a combobox is coded such that something happens when the *user*
selects an item.  Is that what you wanted?  If so, I'd suggest you only load the
entries for the combobox in the Initialize event, and then load the objects in its
Click event.

> Karl
> I'm having trouble with the combo box code, listed below is the code i've
[quoted text clipped - 82 lines]
>> .NET: It's About Trust!
>> http://vfred.mvps.org

Signature

.NET: It's About Trust!
http://vfred.mvps.org

danny - 01 Mar 2007 22:05 GMT
Karl
Could you give me a example of this, i'm a little confused on this
thanks
danny

> Hmmmm, usually a combobox is coded such that something happens when the
> *user* selects an item.  Is that what you wanted?  If so, I'd suggest you
[quoted text clipped - 90 lines]
>>> .NET: It's About Trust!
>>> http://vfred.mvps.org
Karl E. Peterson - 01 Mar 2007 22:21 GMT
> Karl
> Could you give me a example of this, i'm a little confused on this

Okay, add a new UserForm to a document, and put a combobox and a label control on
it.  Then add this code:

  Option Explicit

  Private Sub ComboBox1_Click()
     Label1.Caption = "You selected: " & ComboBox1.Text
  End Sub

  Private Sub UserForm_Initialize()
     Dim i As Long
     For i = 1 To 10
        ComboBox1.AddItem "Item #" & i
     Next i
  End Sub

When you run it, and select items in the list, that selection is reflected in the
Label control.  Your code appears to have combined these two event procedures into
one?

>> Hmmmm, usually a combobox is coded such that something happens when the
>> *user* selects an item.  Is that what you wanted?  If so, I'd suggest you
[quoted text clipped - 94 lines]
>> .NET: It's About Trust!
>> http://vfred.mvps.org

Signature

.NET: It's About Trust!
http://vfred.mvps.org

danny - 05 Mar 2007 13:44 GMT
Karl
Thanks for the code, i was able to modify it some and get it to work, but
i'm having a problem getting the userform to open. I would like to have the
form open by using a macro that way it can be used on more than one
doucment. I looked all over the internet and just can't find any code that
would let me do this with a macro.

thanks
danny

>> Karl
>> Could you give me a example of this, i'm a little confused on this
[quoted text clipped - 122 lines]
>>> .NET: It's About Trust!
>>> http://vfred.mvps.org
Jonathan West - 05 Mar 2007 14:02 GMT
> Karl
> Thanks for the code, i was able to modify it some and get it to work, but
> i'm having a problem getting the userform to open. I would like to have
> the form open by using a macro that way it can be used on more than one
> doucment. I looked all over the internet and just can't find any code that
> would let me do this with a macro.

Take a look at these articles

What do Templates and Add-ins store?
http://www.word.mvps.org/FAQs/Customization/WhatTemplatesStore.htm

Distributing macros to other users
http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm

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

danny - 05 Mar 2007 17:52 GMT
I'm sorry but neither of these articles will help me with what i need.
Macro's are stored with the name of SUB and the marcos name, the VBA code
that is used for the user form is private sub, when i try and use the code
listed below in a macro it wiil not work

Private Sub Form_load()

   frmUserForm1.Show

End Sub

If i try this code below then i get the error that the command frmUserForm1
has been defined.

Sub Macro2()

frmUserForm1.Show
End Sub

>> Karl
>> Thanks for the code, i was able to modify it some and get it to work, but
[quoted text clipped - 11 lines]
> Distributing macros to other users
> http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm
Karl E. Peterson - 06 Mar 2007 01:34 GMT
Put the .Show command in your "macro" (within a standard BAS module), not within the
form module itself.
Signature

.NET: It's About Trust!
http://vfred.mvps.org

> I'm sorry but neither of these articles will help me with what i need.
> Macro's are stored with the name of SUB and the marcos name, the VBA code
[quoted text clipped - 37 lines]
>> Please reply to the newsgroup
>> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
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.