Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Oct 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with import images and resize to Word doc script

    I recently found a great macro on this site that allows you import images into a Word Doc form (Home Inspection Report_Word.doc (please see attached). I am now trying to figure out how one might force the images to be imported at a certain percentage of size (such as 30%)? Does anyone have any experience with scripting something like this? Appreciate any thoughts or examples very much. You can find the examples of the script/macro on pages 4 & 5 (see green buttons).

    Thanks in advance,
    Jason

    this is probably basic, but I am trying to set a button (or actually buttons) to not print in a Word form. The code I am using looks like this:
    Code:
    Sub InsertPic2()
      InsertPic 2
    End Sub
    
    Sub InsertPic3()
      InsertPic 3
    End Sub
    
    Sub InsertPic(n As Integer)
      Dim sFileName As String
      Dim ilImage As InlineShape
      Dim rng As Range
    
      If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
        ActiveDocument.Unprotect
      End If
      With Dialogs(wdDialogInsertPicture)
        .Display
        If .Name <> "" Then
          sFileName = .Name
          Set rng = ActiveDocument.Bookmarks("Pic" & n).Range
          Set ilImage = ActiveDocument.InlineShapes.AddPicture(sFileName, , True, rng)
          With ilImage
          .LockAspectRatio = msoTrue
        .Height = 252
        .Width = 343
            'set any additional properties such as left, top, etc., here
          End With
      End If
      ActiveDocument.Protect wdAllowOnlyFormFields, True
    End With
    End Sub
    How would I set the buttons to not print, but show up visually in the form?

    Any help much appreciated,
    Jason
    Last edited by macropod; 2014-10-25 at 03:27.

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    The simplest way to control image sizes when they're inserted into a document is to insert them into table cells whose dimensions are already fixed. Trying to rely on percentage scaling when you have images taken by different cameras at different resolutions is unreliable at best. For the document in your link, all that would be required for this to work is to split the existing cell in three, with one macrobutton field per cell, then fix the column widths and row height to the required size.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    New Lounger
    Join Date
    Oct 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by macropod View Post
    The simplest way to control image sizes when they're inserted into a document is to insert them into table cells whose dimensions are already fixed. Trying to rely on percentage scaling when you have images taken by different cameras at different resolutions is unreliable at best. For the document in your link, all that would be required for this to work is to split the existing cell in three, with one macrobutton field per cell, then fix the column widths and row height to the required size.
    That's a great idea. Thank you for that suggestion. I am also tying to figure out how to hide the buttons from printing? Any suggestions on that?

    Thanks,
    Jason

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    The buttons, as you call them, are just macrobutton fields. The macros they call could be made to delete the fields themselves as part of their processing, regardless of whether an image is inserted. With the approach suggested, the only VBA code you need is:
    Code:
    Sub InsertPic()
    Dim sFileName As String, iShp As InlineShape
    Dim Rng As Range
    With ActiveDocument
      If .ProtectionType = wdAllowOnlyFormFields Then .Unprotect
      Set Rng = Selection.Cells(1).Range
      With Rng
        .End = .End - 1
        .Text = vbNullString
      End With
      With Dialogs(wdDialogInsertPicture)
        .Display
        If .Name <> "" Then sFileName = .Name
      End With
      .InlineShapes.AddPicture FileName:=sFileName, LinkToFile:=False, Range:=Rng
      .Protect wdAllowOnlyFormFields, True
    End With
    End Sub
    Each macrobutton field can call the above macro.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    You can set the button's Font property to 'Hidden'
    Then change the options to display hidden text on screen but not to print it.

    Those option settings can be done in code.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    As already discussed here: http://windowssecrets.com/forums/sho...l=1#post971152, there is no 'button'. You're using macrobutton fields and the same code that inserts the images can be used to delete the fields - regardless of whether an image is inserted.

    PS: Since your threads are related to the same topic, I've merged them.
    Last edited by macropod; 2014-10-25 at 03:29.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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