Consulting

Results 1 to 3 of 3

Thread: Runtime Error '6' - Overflow

  1. #1

    Runtime Error '6' - Overflow

    Hi Guys,

    I have a template that prompts the user to walk it to a folder that contains photos.

    The program searches the folder with any .jpg or .jpeg file and puts it in a table.

    The table is 3 columns (column 1 is photo info [date/time/camera used/file name] column 2 is blank [left for descriptions] and column 3 gets the photo and hyperlink to the file)

    Its been working, but now it will sometimes give me a runtime 6 overflow error.

    I thought it was due to a large number of .jpg files, but when the folder has only a few, or even just 1 it gives the overflow error.

    The code in its entirety is below, you have to start with an empty row of 3 columns for it to properly run.


    [vba]
    Sub phot()

    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
    Dim pth As New MSComDlg.CommonDialog
    Dim r As Integer
    Dim t As Integer
    Dim objExif As New ExifReader
    Dim txtExifInfo As String


    entry = 0
    'Browse to folder
    With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    If .Show = -1 Then
    pname = .SelectedItems(1)
    Else
    MsgBox "You pressed Cancel"
    Exit Sub
    End If
    End With

    'file path for pictures
    Set fso = New FileSystemObject
    Set fol = fso.GetFolder(pname)

    '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
    'ActiveDocument.Tables(1).Rows(entry).Select
    'entry = entry + 1
    'gives reference to cell 1 then adds text
    Set cel = roe.Cells(1)
    cel.Range.Text = pic.Name
    entry = entry + 1

    objExif.Load pic.Path
    '
    'FILL IN THE CELL INFORMATION
    '
    'Selection.MoveDown Unit:=wdLine, Count:=4, Extend:=wdExtend
    'Selection.Delete Unit:=wdCharacter, Count:=1
    cel.Range.Text = pic.Name & vbCr & objExif.Tag(Model) & vbCr & pic.DateLastModified & vbCr & pic.Size & " Bytes"
    'gives reference to cell 3 then adds pic
    Set cel = roe.Cells(3)
    'add photo
    Set ish = cel.Range.InlineShapes.AddPicture(FileName:=pic.Path, LinkToFile:=False, SaveWithDocument:=True)
    'add hyperlink..."text" would place text as the hyperlink
    Set MyLink = ActiveDocument.Range.Hyperlinks.Add(ish, pic.Name, , , "")
    End If
    Next
    ActiveDocument.Tables(1).Rows(2).Delete

    End Sub
    [/vba]
    The line causing the overflow is

    [vba]objExif.Load pic.Path[/vba]
    I'm not sure how to resolve the error. Any help would be greatly appreciated.
    Thanks,

    Abdullah

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Hi Abdullah,
    I'm not sure how helpful I can be, because I am not familiar with the ExifReader object. But if the load method does not like your input, it's going to be something about the value in pic.Path. Check to make sure that the path has a value, sometimes things will throw an overflow if they aren't expecting a nullstring. Another thing to check is to see if it makes a difference converting the path to a dos "short path" before passing the string to the method (In other words use the ShortPath property).

    Not sure if any of that will help, but hopefully it will get you started.
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I agree. Use a Watch and see what is going into your variables.

Posting Permissions

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