none
Macro - Import, Resize, Adjust Format, Position, Insert Text Box, Lines RRS feed

  • Question

  • Hello,

    I have a challenge for those of you that are really good with macros. I am a beginner with macros and would like to use them to make my work a little easier. I have a multitude of images of cells that I have to import into word, change the format to tight, resize each image, equally space them on a sheet, insert lines to differentiate each picture from another one, and then add a text box at the bottom of each of these images to add what type of cells they are. I would like this to be done automatically with the click of a macro function if possible. I have code to change the size of these images and to import them, but I don't know how to add everything else or even these codes to the new codes. If someone could help me do the following procedures in this sequential order, I would very much appreciate it:

    1) Import a specific folder of pictures, 2) select all of these pictures to change their format to "tight," 3) resize all of these pictures to Height: 2.00 inches and width: 2.70833333333333 inches, 4) place eight of these pictures in 4 rows and 2 columns next to one another, 5) add a bolded dark line between each picture to differentiate the pictures, and 6) add a text box to the bottom of each of these panels with a black background (each individual picture, 8 text boxes per sheet). 

    If someone could figure out how to do this with a click of a button, it would be a huge time saver! 

    Thank you!!

    Friday, May 31, 2013 6:13 PM

Answers

  • 1) Import a specific folder of pictures

    You can use DIR$ function to traverse all image files in a specific folder:

    'Insert all bmp files in the specific folder to the document
    
    Dim FolderName As String
    Dim FileName As String
    Dim FullPath As String
    
    FolderName = "D:\myFolder\"        'Don't forget the last "\"
    FileName = Dir$(FolderName & "*.bmp")
    
    Do While FileName <> ""
    FullPath = FolderName & FileName
    Shapes.AddPicture FullPath
    FileName = Dir$()
    Loop

    2) select all of these pictures to change their format to "tight,"

    3) resize all of these pictures to Height: 2.00 inches and width: 2.70833333333333 inches

    You can set wrap text via Shape.WrapFormat.Type Property. You can specify Shape.Height Property and Shape.Width Property for resizing.

    For Each iShape In ActiveDocument.Shapes
        iShape.Height = InchesToPoints(2)
        iShape.Width = InchesToPoints(2.7083333333)
    Next iShape
    
    Range.ShapeRange.WrapFormat.Type = wdWrapTight

    Or you can also specify the width and height in the Shapes.AddPicture Method

    4) place eight of these pictures in 4 rows and 2 columns next to one another, 5) add a bolded dark line between each picture to differentiate the pictures, and 6) add a text box to the bottom of each of these panels with a black background (each individual picture, 8 text boxes per sheet). 

    You can specify the location of picture in the Shapes.AddPicture Method. To add the solid line in the document, you can use Shapes.AddLine Method (Word).

    To add the textbox, go to Developer tab->Controls->Legacy Tools->ActiveX Controls->Text Box.

    To change the text box background color and text color:

    TextBox1.BackColor = RGB(0, 0, 0)
    TextBox1.ForeColor = RGB(255, 0, 0)

    Hope these might help you.

    Furthermore, I suggest you using InlineShapes Collection Object instead of Shape. The Shape objects are anchored to a range of text but are free-floating, you would face complicated issue of relocating them.

    Regards,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 4, 2013 1:36 PM
    Moderator

All replies

  • 1) Import a specific folder of pictures

    You can use DIR$ function to traverse all image files in a specific folder:

    'Insert all bmp files in the specific folder to the document
    
    Dim FolderName As String
    Dim FileName As String
    Dim FullPath As String
    
    FolderName = "D:\myFolder\"        'Don't forget the last "\"
    FileName = Dir$(FolderName & "*.bmp")
    
    Do While FileName <> ""
    FullPath = FolderName & FileName
    Shapes.AddPicture FullPath
    FileName = Dir$()
    Loop

    2) select all of these pictures to change their format to "tight,"

    3) resize all of these pictures to Height: 2.00 inches and width: 2.70833333333333 inches

    You can set wrap text via Shape.WrapFormat.Type Property. You can specify Shape.Height Property and Shape.Width Property for resizing.

    For Each iShape In ActiveDocument.Shapes
        iShape.Height = InchesToPoints(2)
        iShape.Width = InchesToPoints(2.7083333333)
    Next iShape
    
    Range.ShapeRange.WrapFormat.Type = wdWrapTight

    Or you can also specify the width and height in the Shapes.AddPicture Method

    4) place eight of these pictures in 4 rows and 2 columns next to one another, 5) add a bolded dark line between each picture to differentiate the pictures, and 6) add a text box to the bottom of each of these panels with a black background (each individual picture, 8 text boxes per sheet). 

    You can specify the location of picture in the Shapes.AddPicture Method. To add the solid line in the document, you can use Shapes.AddLine Method (Word).

    To add the textbox, go to Developer tab->Controls->Legacy Tools->ActiveX Controls->Text Box.

    To change the text box background color and text color:

    TextBox1.BackColor = RGB(0, 0, 0)
    TextBox1.ForeColor = RGB(255, 0, 0)

    Hope these might help you.

    Furthermore, I suggest you using InlineShapes Collection Object instead of Shape. The Shape objects are anchored to a range of text but are free-floating, you would face complicated issue of relocating them.

    Regards,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 4, 2013 1:36 PM
    Moderator
  • Hi CancerChemist,

    Your post looks to me like a work order RFQ and not a request for help with a specific coding problem. Damon has very generously provided you with most all of the components that you can use to help write your code.

    Beyond that I think it's now up to you to put the pieces together.

    Just my volunteering community member opinion... :-)


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, June 4, 2013 2:30 PM