vba - How to add a file from the active document directory -


I have a document that every time I need to insert a specific item into my document, a VBA Creates a template page from the script, it's a great time saver, it contains an image in which I found the foundation of a work through which this image is inserted and the text wrap it where I want, though File path is an integer i It would like the file path to specify the image file as the active document in the same directory, so I can move the folder to a different location, will not break the macro.

The problem is one beyond my VBA skills, I've worked, I should probably use the ActiveDocument.Path command, but I'm not sure how your support is appreciable. Thank you

Below is my code:

  Sub Inser_Wrapped_Image () Dim shp as set size in Shp = ActiveDocument.Shapes.AddPicture (_FileName: = "C: \ Users \ Edoardo \ Documents \ My Work \ PhD \ SkyDrive \ Tutoring \ Houria \ Image Replacement.jpg ", _ SaveWithDocument: = True, _ Anchor: = Selection.Range) with SP. WrapFormat.Type = wdSquare .Left = 246 .. = 50 With = 250. I end up with the height = 188 end   

I tried to write it but freeze the word for a few seconds and then does nothing:

  sub-insert_image () default shp-like size set shp = ActiveDocument.Shapes.AddPicture (_FileName: = ActiveDocument.Path and "\ Image.jpg", _SaveWithDocument: = True, _ anchor: = selection .ange) ending sub < / code>   

Try this:

  sub inser_Wrapped_Image () Dim Size like shp dim dimggath as string imgpath = ThisDocument.Path imgpath = imgpath & amp; "\" & Amp; Set the "Image Replacement .Jpg" shp = thisDocument.Shapes.AddPicture (_FileName: = imgpath, SaveWithDocument: = True, _Anchor: Selection.Range) with SP. WrapFormat.Type = wdWrapSquare .Left = 246 Hat = 50 .Width = 250 .ightight = 188 end with end   

I used to explicitly use the ThisDocument to load the picture Which included the macro
If you want to paste it with ActiveDocument , think both ways.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -