Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 35 of 35

Thread: Macro Incorporating JPEG Files

  1. #21
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I'm sorry I don't know of any reason why that should fail. Can you post a sample document?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  2. #22
    Tony,

    A sample file is not attached, couldn't seem to get it under 19kb. But the first row is not the first row on every page (which is what I'm trying to do). The code is at the bottom, perhaps you could run it and see if it works as a header row for you.

    Set tbl = ActiveDocument.Range.Tables(1)
    ActiveDocument.Tables(1).Rows(1).HeadingFormat = True

    doesn't seem to do anything



    Also, as a few side notes, I've tried to make the text in column 1 smaller with

    selection.font.size=10

    but the font remains unaffected.



    Also, I am trying to make the text only in the header rows centered...I'ved used a combination of

    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    and
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft

    But unfortunately my placement must be off or something, because I've been able to center just the text after the first line, leaving line 1 aligned to the left (the opposite of what I was trying to do).




    Sub picinf()
    'Variables
    Dim fso As FileSystemObject
    Dim fol As Folder
    Dim pic As File
    Dim tbl As Table
    Dim roe As Row
    Dim cel As Cell
    Dim ish As InlineShape

    'file path for pictures
    Set fso = New FileSystemObject
    Set fol = fso.GetFolder("C:\Documents and Settings\Administrator\My Documents\My Pictures\Copy of 4-11-2006")
    'CREATING TABLE
    '1 row 3 columns
    Set tbl = ActiveDocument.Range.Tables.Add(ActiveDocument.Range(0, 0), NumRows:=1, NumColumns:=3)
    'column sizes
    tbl.Columns(1).Width = InchesToPoints(1.5)
    tbl.Columns(2).Width = InchesToPoints(4)
    tbl.Columns(3).Width = InchesToPoints(1.75)
    'column labels
    Set cel = ActiveDocument.Tables(1).Rows(1).Cells(1)
    cel.Range.Text = "Info"
    Set cel = ActiveDocument.Tables(1).Rows(1).Cells(2)
    cel.Range.Text = "Description"
    Set cel = ActiveDocument.Tables(1).Rows(1).Cells(3)
    cel.Range.Text = "Picture"
    'set row 1 as header for each page
    Set tbl = ActiveDocument.Range.Tables(1)
    ActiveDocument.Tables(1).Rows(1).HeadingFormat = True
    'FILLING IN TABLE
    For Each pic In fol.Files
    If LCase(Right(pic.Path, 4)) = ".jpg" Or LCase(Right(pic.Path, 5)) = ".jpeg" Then
    'add row and give reference to it
    Set roe = ActiveDocument.Tables(1).Rows.Add
    'gives reference to cell 1 then adds text
    Set cel = roe.Cells(1)
    cel.Range.Text = pic.Name & vbCr & pic.DateCreated
    Set cel = roe.Cells(1)
    Selection.Font.Size = 10
    'gives reference to cell 3 then adds pic
    Set cel = roe.Cells(3)
    Set ish = cel.Range.InlineShapes.AddPicture(FileName:=pic.Path, LinkToFile:=False, SaveWithDocument:=True)
    End If
    Next
    End Sub

  3. #23
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Odd! After running it if you look at the Table Menu you will see the row set as a Heading Row. I swapped it a few times and it eventually corrected itself - I don't know why at the moment. I have to go out now but will look at it later.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #24
    Tony,

    I got the formating sorted out...including the header stuff.

    The last thing that I have is, the program you started me off with....you had to type the file path into the code. Is there a way to have it set up where someone would run the macro, and have a prompt come up where they could step to the file path (similar to how file-open works)?

    Thanks for all your help thus far, I can finally see the finish

  5. #25
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Glad you got it sorted. What was happening was that the Heading Row status was being set on the only row in the table. When new rows were added they inherited the status so that every row had it so it became something Word could not honour. The thing to do is to set it after there is at least one other row - in practice, after the loop building it the table.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #26
    Tony,

    So for the prompt, I've determined that I need to reference Microsoft Common Dialogue Control and then use Show Open....I've tried making a form that I would edit, but that has confused and frustrated me.

    How would you go about taking the hard coded file path out of the program and replacing it with a prompt that the user would use to step to the directory, or files?

  7. #27
    Tony,

    Please disreguard the previous post...I used an input box to request the correct path from the user, and it works alright. However, my question is, after running the program I ended up with a word file that was about 92Mb in size.

    I believe the reason for that is because the program took shrunk down images of the files, instead of using the thumbnails. Do you know of a way I can use thumb nails instead of small images? In order to keep completed file size to minimum?

    Also, to expand on that question, I noticed that the pictures don't completely fill the 3rd column cell. Is there a way to adjust the thumbnails (once they are thumbnails) to fit the exact cell size (even if it's writing the dimensions into the code)?

    Please let me know...

    Thank you,
    Abdullah

  8. #28
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Sorry, I'm catching up slowly. Try this to pick up a folder. You'll want to take appropriate action and not just the msgboxes of course.
    [VBA]
    With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    If .Show = -1 Then
    MsgBox .SelectedItems(1)
    Else
    MsgBox "You pressed Cancel"
    End If
    End With

    [/VBA]

    As for compression - I'm not much of a picture person and don't know about VBA for this - try selecting a picture (any one), right clicking, selecting Format Picture and on the Picture tab, pressing Compress... Then choose to compress all pictures in document.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  9. #29
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    AFAIK, you can't pick up thumbnails directly (do they necessarily exist anyway - or are they created in the fly?) but if you turn off autofit on the table (TableRef.AllowAutoFit= False) the pictures should be automatically scaled down to the width of the column (but will still want compressing). I don't think they'll scale up if the column is too wide though.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  10. #30
    AFAIK? I dont know that anogram. Anyways, those both worked extremely well for me, both the browsing to the folder path and the auto-fit advice.

    One last question, I know that currently I'm pulling the picture info that is displayed (date/time/name, etc) from the pic itself....i.e. get the same info by right clicking the picture and going to properties.

    One thing I would also like to include is the camera make/model that took the picture. That info is not contained in the fields that show when you right click and go to properties, however is contained in the EXIF information. Do you know of a way for me to get at that info? Also, the date created info seems to be the date the pic was loaded on the computer (and some don't even show times). Do you know of a way to pull date/time from the EXIF information, in addition to the camera make/model?
    Thanks,

    Abdullah

  11. #31
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    As Far As I Know. Having just formatted that I seem to recall there was a list of these somewhere on the site - I'll see if I can locate it.

    Sorry I know nothing about extended properties of Images - If Windows can show them there's probably an API but I have no idea what it may be.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  12. #32
    Tony,

    Again, ignore the above post...except for the part where I ask about AFAIK. For a picture I figured out (when going to properties in the general tab) that the created field (also matches with picture taken, in the summary tab/advanced view) is the date it was loaded onto a computer, and the modified is when it was actually taken.

    cel.Range.Text = pic.Name & vbCr & pic.DateCreated & vbCr & pic.Size & " Bytes"


    I tried changing DateCreated to DateModified however that just throws a compile error at me. How would I go about making that change?

    Also under properties ->summary -> advanced....it shows me the camera make and camera model. I need to encorporate those fields as well....so I was wondering if you knew how I could get the macro you'd greatly helped me with to output Modifed (for the correct picture taken time)(properies --> general) and equipment make (properies --> summary/advanced) and camera model (properies --> summary/advanced)
    Thanks,

    Abdullah

  13. #33
    If you could find that list (of what info is available/how to reference it) that would be fantastic
    Thanks,

    Abdullah

  14. #34
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I've found the link to the glossary - http://www.vbaexpress.com/forum/glossary.php - but it appears the feature has been removed; I don't know why.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  15. #35
    Tony,

    You have no idea where I could possibly find another copy of the glossary? I'm done with the project...with the exception of the info added to the info column. Again, I was hoping to include the date modified instead of the date created, and the camera make/model that was used. A copy of the glossary of info I could include (what the fields are named) would be a HUGE help in finishing the project.

    Thanks
    Thanks,

    Abdullah

Posting Permissions

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