Attach documents in Excel and then view them.

jpmccreary

New Member
Joined
Jul 21, 2010
Messages
11
I have an Excel workbook that allows users to attach documents. Once attached, I need an option to view/open these documents. I need to get the name of the open document so I can continue to control via the Excel workbook. Any ideas? Below is the full code for the View sub. I get "Run-time error 429: ActiveX component can't create object" when I try to assign Attachmentname the Activedocument name. I am sure it is the wrong syntax but I have not been able to find anything that works.

Private Sub cbView_Click()
Dim iIndex As Integer
Dim DocName As String
Dim MerlinName As String
Dim AttachmentName As String

MerlinName = ActiveWorkbook.name

iIndex = Me.lbAttached.ListIndex
If iIndex = -1 Then Exit Sub

DocName = Me.lbAttached.Value

ActiveWorkbook.Worksheets("DOCS").OLEObjects(DocName).Activate
AttachmentName = ActiveDocument.name

Workbooks(MerlinName).Activate
Range("OpenWorkbookName").Offset(iIndex + 1, 0) = AttachmentName

GetObject (AttachmentName)
ActiveWindow.WindowState = xlMaximized
Me.Hide
frmCloseAttachment.Show
End Sub
 

tweedle

Well-known Member
Joined
Aug 1, 2010
Messages
1,559
What does this do for you?

Code:
Dim objDoc As OLEObject
'<snip>
 
Set objDoc = ActiveWorkbook.Worksheets("DOCS").OLEObjects(DocName)
objDoc.Activate
Debug.Print objDoc.Name 
AttachmentName = objDoc.Name
 

Forum statistics

Threads
1,082,250
Messages
5,364,020
Members
400,774
Latest member
Goldi paul

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top