![]() |
|
|
|
#1
|
|||
|
|||
|
Code:
Sub threePPg()
'
' threePPg Macro
' Macro recorded 3/14/2008
'
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Rows.Delete
Selection.TypeBackspace
Application.DisplayAutoCompleteTips = True
ActiveDocument.AttachedTemplate.AutoTextEntries("3Ppg").Insert Where:= _
Selection.Range, RichText:=True
Selection.TypeBackspace
ActiveDocument.AttachedTemplate.AutoTextEntries("addmore").Insert Where:= _
Selection.Range, RichText:=True
Selection.TypeBackspace
'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
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
Last edited by johndrew; 07-04-2018 at 08:12 AM. Reason: Dim FSO As FileSystemObject |
|
#2
|
||||
|
||||
|
Change
Code:
Dim FSO As FileSystemObject Code:
Dim FSO as Object Change Code:
Set FSO = New FileSystemObject Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
Note you have some undeclared variables in use and some declared variables that are not used.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
It now says fol=folder
Can't find project or Library |
|
#4
|
||||
|
||||
|
For FSO operations you need to check Microsoft Scripting Runtime in the available object libraries. That provides access to the DLL C:\Windows\SysWOW64\scrrun.dll
https://stackoverflow.com/questions/...in-vba#3236348
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Testing for 'Object has been deleted' error
|
Cosmo | Word VBA | 14 | 04-04-2018 01:58 PM |
| Organization Chart Object Changes to Equation Object? | jhcoleman53 | Drawing and Graphics | 0 | 08-24-2017 07:09 AM |
| set row object variable error | CLoos | Excel Programming | 6 | 03-10-2017 04:48 PM |
| Problem: object library invalid or contains references to object definitions | aligahk06 | Office | 0 | 08-19-2010 12:29 PM |
| Could not load this object as this object is not present in your computer | k.gaurav | Office | 0 | 08-17-2009 09:57 PM |