Hi,
This is what the code looks like now. The areas where I need input are marked with the comments:
[VBA] Public FileToOpen, NameOfFile(50) As String
'Public NewButton As Control Need help here on how to initialize a commandbutton and commandbar
'Public PopupBar1 As ???????????
Sub trial1()
j = 0
With Application.FileSearch
.NewSearch
.FileType = msoFileTypeAllFiles
.LookIn = "C:\Lincoln\Projects\ZNA Templates (Buffalo)"
.Execute
Set PopupBar1 = CommandBars.Add("Template Toolbar", msoBarFloating)
If .FoundFiles.Count > 0 Then
For i = 1 To .FoundFiles.Count
FileToOpen = .FoundFiles(i)
FName = Left(" | " & Trim(Str(i)) & " " & Trim(Mid(.FoundFiles(i), 45)), 30)
Set NewButton = PopupBar1.Controls.Add(Type:=msoControlButton)
With NewButton
.Caption = FName
.Style = msoButtonCaption
.OnAction = "DeleteToolbar"
End With
NameOfFile(j) = .FoundFiles(i)
Next i
With PopupBar1
.Width = 5
.Height = 290
End With
PopupBar1.Visible = True
Else
MsgBox "There are no files in this location", vbCritical
End If
End With
End Sub
Sub DeleteToolbar()
CommandBars("Template Toolbar").Delete
' This part works in the sense that it opens up
' the last file in the collection. I want the
' button selected file to open.
Documents.Open NameOfFile(j)
UserForm2.Show
End Sub
[/VBA]
As you can see, I've worked my brain over this, but since I'm not that good with VB as yet, I am finding it rather difficult in even understanding the help file. I've learned VB only through trial and error, and errors are more that I've encountered with average learning. Please help.