Hi, I have a file that contains two columns: A - file path and B - Title. To select a file, I double click in column A (let's say, A14), which opens an Explorer window. I make my selection and the path of the selected file is inserted in the double clicked cell. Now, to get the title of said file, I double click in column B (B14). If the file is a workbook, the title property is written in B14. However, if the file is a Word document, I get an error (424). I have tried to find a solution but I can't find one.
There are 4 codes:
- Dialog (opens the windows allowing me to select the file) - works smoothly
- Worksheet_BeforeDoubleClick - works for column A. As for column B, it works only if the file is a workbook
- GetTitleExcel (Function) - works as intended
- GetTitle word (Function)
Here are the codes:
I presume the problem is either with the GetTitleWord function or with the way the macro open/reads the Word file. Any suggestions? Thanks!
There are 4 codes:
- Dialog (opens the windows allowing me to select the file) - works smoothly
- Worksheet_BeforeDoubleClick - works for column A. As for column B, it works only if the file is a workbook
- GetTitleExcel (Function) - works as intended
- GetTitle word (Function)
Here are the codes:
VBA Code:
Function GetTitleExcel()
GetTitleExcel = ThisWorkbook.BuiltinDocumentProperties(1)
End Function
Function GetTitleWord()
GetTitleWord = ActiveDocument.BuiltinDocumentProperties("Title")
End Function
Sub Dialog()
Dim lct As Long
Dim ac As Range
Set ac = ActiveCell
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Show
For lct = 1 To .SelectedItems.Count
ac.Worksheet.Hyperlinks.Add _
Anchor:=ac, Address:=.SelectedItems(lct), _
TextToDisplay:=.SelectedItems(lct)
Next lct
End With
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A14:A20")) Is Nothing Then
Call Dialog
End If
If Not Intersect(Target, Range("B14:B20")) Is Nothing Then
Dim ext As String
Dim title As String
ext = ActiveCell.Offset(0, 1)
Application.ScreenUpdating = False
ActiveCell.Offset(0, -1).Select
Selection.Hyperlinks(1).Follow NewWindow:=False
If ext = "xls*" Then
title = GetTitleExcel()
Else
title = GetTitleWord()
End If
ActiveWindow.Close
ActiveCell.Offset(0, 1) = title
Application.ScreenUpdating = True
End If
End Sub
I presume the problem is either with the GetTitleWord function or with the way the macro open/reads the Word file. Any suggestions? Thanks!