PDA

View Full Version : Letter Template database in Excel Forms.



chacanger
03-17-2012, 11:59 AM
Hello

I've recently tried to make a program to allow a user to browse through a load of letter templates and the odd xls sheet within a few folders. I found one way of showing a preview of the file by making the system open up the word document and copying the text into a text box on my form. The problem is that this is slow and slighly buggy.

So my first question is, is there a control or solution better to the one I mentioned above.

Second issue is that I need a tree view to show a certain folder and have subfolders split by the + sybols, however I'm not sure how to do this.

For reference here is the code I have used so far that is seen within the user form.

Const LBFileLocation As String = "D:\Documents and Settings\admin\Desktop\Letter Temps"
Private Sub NavigationPane_NodeClick(ByVal Node As MSComctlLib.Node)
'####Brings up a preview of the document the user has selected in the tree view.####
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
On Error GoTo SkipCode
If PreviewToggle = False Then Exit Sub
If Right(LBInterface.NavigationPane.SelectedItem, 3) = "doc" Then 'Word Documents
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(LBFileLocation & "\" & LBInterface.NavigationPane.SelectedItem)

With wdDoc.ActiveWindow.Selection
.WholeStory
.Copy
End With

With LBInterface.LetterPreview
.Value = ""
.Locked = False
.Paste
.Locked = True
End With

wdApp.Quit
ElseIf Right(LBInterface.NavigationPane.SelectedItem, 3) = "xls" Then 'Excel Documents

SkipCode: 'If the file is a temp file

LBInterface.LetterPreview.Value = "No preview available for this specific file."
End If
End Sub
Private Sub OpenBTN_Click()
'####Opens the document selected by the user.####
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
If Right(LBInterface.NavigationPane.SelectedItem, 3) = "doc" Then 'Word Documents
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(LBFileLocation & "\" & LBInterface.NavigationPane.SelectedItem)

wdApp.Visible = True
ElseIf Right(LBInterface.NavigationPane.SelectedItem, 3) = "xls" Then 'Excel Documents
Workbooks.Open Filename:=LBFileLocation & "\" & LBInterface.NavigationPane.SelectedItem
End If
End Sub
Private Sub PreviewToggle_Click()
If PreviewToggle = False Then LBInterface.LetterPreview.Value = "Preview's have been switched off."
End Sub
Private Sub UserForm_Initialize()

Dim fs As FileSearch, ws As Worksheet, i As Long
Set fs = Application.FileSearch
With fs
.SearchSubFolders = True ' set to true if you want sub-folders included
.FileType = msoFileTypeAllFiles 'can modify to just Excel files eg with msoFileTypeExcelWorkbooks
.LookIn = "D:\Documents and Settings\admin\Desktop\Letter Temps" 'modify this to where you want to serach
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
LBInterface.NavigationPane.Nodes.Add , , , Replace(.FoundFiles(i), LBFileLocation & "\", "")
Next
Else
MsgBox "No files found"
End If
End With
End Sub

http://i860.photobucket.com/albums/ab168/chacanger/Misc/PreviewPX.jpg

If someone could suggest better solutions or knows of any controls etc to make this better I would much appriciate it.