+ Reply to Thread
Results 1 to 14 of 14

Macro trying to insert an image

  1. #1
    Registered User
    Join Date
    04-25-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    6

    Macro trying to insert an image

    Hello,

    I attached my document....What im trying to do is when the dialogue box appears and a person clicks "browse" and selects a .jpg image I want the path to the image to display in the text box above the "browse" button.

    For some reason the path isn't showing...Any idea's why??

    Thanks!
    example.xlsm

  2. #2
    Registered User
    Join Date
    04-25-2012
    Location
    portsmouth,england
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro trying to insert an image

    I think that might be because you used: TextBox1_Change(), meaning that it will only write the path if you write something on TextBox1
    Hope that helps

  3. #3
    Registered User
    Join Date
    04-25-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro trying to insert an image

    Okay, fantastic, I ll try editing that! Any idea what I should edit it too? I tried just TextBox1(), but VBA Editor doesn't like that

    Much appreciated!

    Quote Originally Posted by uduyt View Post
    I think that might be because you used: TextBox1_Change(), meaning that it will only write the path if you write something on TextBox1
    Hope that helps

  4. #4
    Registered User
    Join Date
    04-25-2012
    Location
    portsmouth,england
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro trying to insert an image

    No problem!

  5. #5
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Macro trying to insert an image

    Ok...so a couple of things.

    1. You need to set the value of the textbox upon initialization of the userform. This is accomplished via:
    Please Login or Register  to view this content.
    (Copy Paste in same location as your other form code)

    2. I switched your variable declaration to String from Variant as a file path is exactly that, a string. The revised CommandButton1_Click would then look like:
    Please Login or Register  to view this content.
    I'm not sure about your TextBox1_Change code. I am fairly certain that if its creation was an attempt to do what we have just done, it is now unnecessary and can be removed.

    Hope this helps.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  6. #6
    Registered User
    Join Date
    04-25-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro trying to insert an image

    Any idea what I should change it too? If i change it to just TextBox1()
    When I try and use the form, i get a VBA Error saying, "Compile Error, Member already exists in an object module from which this object module derives"

    Quote Originally Posted by uduyt View Post
    No problem!

  7. #7
    Registered User
    Join Date
    04-25-2012
    Location
    portsmouth,england
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro trying to insert an image

    I'm not sure, but you can always change it to: TextBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    this means that every time you move the mouse the text box will equal your path

  8. #8
    Registered User
    Join Date
    04-25-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro trying to insert an image

    Fantastic! Works like a beauty.

    Now for the hard part...When the "Create Name Tags" button is clicked, it triggers Word to open, formats the table, and inserts the names...

    I attached the new Excel document, with the working form. Now when the "create name tags" button is clicked it has to trigger MS-Word, and format the document for the labels. The button works, however when its clicked it says, "Compile Error, User-defined type not defined"

    Any ideas why this could be now?exampleweb.xlsm


    Quote Originally Posted by uduyt View Post
    I'm not sure, but you can always change it to: TextBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    this means that every time you move the mouse the text box will equal your path

  9. #9
    Registered User
    Join Date
    04-25-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro trying to insert an image

    I should also mention, the reason Im asking on the form to "select logo" - is because this logo is going to get passed to the Word document so the logo can display on the label in the Word document

    I was thinking Id add something like this, I was adding this subrountine between the code for the "browse" button, and the code that triggers the word document, but VBA editor doesn't seem to like that?

    Sub pass_image()
    Dim appwd As Object
    Set appwd = GetObject(, "Word.Application")
    appwd.Visible = True
    appwd.documents.Add
    appwd.Selection.Paste (wdPasteDefault)
    End Sub
    Last edited by sdedeveloper; 04-25-2012 at 03:39 PM.

  10. #10
    Registered User
    Join Date
    04-25-2012
    Location
    portsmouth,england
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro trying to insert an image

    Have you checked the reference box in the tools bar?
    BTW sorry for the delay

  11. #11
    Registered User
    Join Date
    04-25-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro trying to insert an image

    Hey

    No worries man!

    So I got it all working, Excel triggers the Word document...Word opens. The code works. Now the issue Im having is I have to pass the image that the user selects, and the names from the Excel sheet, into Word...I did all the coding for it, but for some reason Excel isnt passing the information to word...

    Can take a gander through the attachment if you want, see if there is anything i missed.

    exampleweb.xlsm

    Quote Originally Posted by uduyt View Post
    Have you checked the reference box in the tools bar?
    BTW sorry for the delay

  12. #12
    Registered User
    Join Date
    04-25-2012
    Location
    portsmouth,england
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro trying to insert an image

    I'm sorry but I don't know much about working with word through excel code, but have a look at this thread, it might help:
    http://www.exceltip.com/show_tip/App...Excel/465.html

  13. #13
    Forum Contributor
    Join Date
    04-03-2011
    Location
    India
    MS-Off Ver
    Excel 2015
    Posts
    122

    Re: Macro trying to insert an image

    Hi Uduyt,

    Give us an idea to implement or else trying working out

  14. #14
    Registered User
    Join Date
    04-25-2012
    Location
    portsmouth,england
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro trying to insert an image

    It's just difficult because I can't test it myself, as i haven't added the reference

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1