Results 1 to 2 of 2

Thread: inserting bullets in a word document using vb code

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    19

    Question inserting bullets in a word document using vb code

    i have a code that lists files in the folder and its subfolders. but it needs to be bulleted the code works fine , puts proper bullets in the first looping but when it moves to the second folder the indent is gone. heres the code:

    listfiles is a function that displays the files in a folder.

    VB Code:
    1. Sub listfiles(folder2 As String)
    2.    
    3.     With wrdobj.FileSearch
    4.         .LookIn = folder2
    5.         .FileType = msoFileTypeAllFiles
    6.         .Execute
    7.         totalfiles = .FoundFiles.Count
    8.         If totalfiles > 0 Then
    9.         Dim i As Integer
    10.         i = 1
    11.        
    12.         While totalfiles > 0
    13.            
    14.             wrdobj.Selection.TypeText Text:=Right(.FoundFiles.item(i), Len(.FoundFiles.item(i)) - InStrRev(.FoundFiles.item(i), "\")) & vbCrLf
    15.             totalfiles = totalfiles - 1
    16.             i = i + 1
    17.         Wend
    18.             wrdobj.Selection.Range.ListFormat.ListOutdent
    19.             wrdobj.Selection.Range.ListFormat.RemoveNumbers wdBulletGallery
    20.         Else
    21.             wrdobj.Selection.Range.ListFormat.RemoveNumbers wdBulletGallery
    22.             wrdobj.Selection.Range.ListFormat.ListOutdent
    23.            
    24.         End If
    25.     End With
    26.    
    27. End Sub
    28.  
    29.  
    30. Dim filobj As New FileSystemObject
    31.                 Dim subfolder As Folder
    32.                 Dim mainfolder As Folder
    33.                 Dim nestedfolder As Folder
    34.                 Set mainfolder = filobj.GetFolder(selectedfolder)
    35.                 total = total + mainfolder.Files.Count
    36.  
    37.                    
    38.                    
    39.                     wrdobj.Selection.TypeText mainfolder.Name & vbCrLf
    40.                     If mainfolder.SubFolders.Count > 0 Then
    41.                        
    42.                         For Each subfolder In mainfolder.SubFolders
    43.                        
    44.                             wrdobj.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=wrdobj.ListGalleries(wdBulletGallery).ListTemplates(2)
    45.                             wrdobj.Selection.Range.ListFormat.ListIndent
    46.                             wrdobj.Selection.TypeText subfolder & vbCrLf
    47.                             wrdobj.Selection.Range.ListFormat.RemoveNumbers wdBulletGallery
    48.                            
    49.                             If subfolder.SubFolders.Count > 0 Then
    50.                                 For Each nestedfolder In subfolder.SubFolders
    51.                                    
    52.                                     wrdobj.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=wrdobj.ListGalleries(wdBulletGallery).ListTemplates(3)
    53.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    54.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    55.                                     wrdobj.Selection.TypeText nestedfolder & vbCrLf
    56.                                     wrdobj.Selection.Range.ListFormat.RemoveNumbers wdBulletGallery
    57.                                    
    58.                                     wrdobj.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=wrdobj.ListGalleries(wdBulletGallery).ListTemplates(1)
    59.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    60.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    61.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    62.                                     listfiles (nestedfolder)
    63.                                 Next
    64.                                     wrdobj.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=wrdobj.ListGalleries(wdBulletGallery).ListTemplates(3)
    65.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    66.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    67.                                     listfiles (subfolder)
    68.                             Else
    69.                                     wrdobj.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=wrdobj.ListGalleries(wdBulletGallery).ListTemplates(3)
    70.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    71.                                     wrdobj.Selection.Range.ListFormat.ListIndent
    72.                                     listfiles (subfolder)
    73.                             End If
    74.                            
    75.                        Next
    76.                         wrdobj.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=wrdobj.ListGalleries(wdBulletGallery).ListTemplates(2)
    77.                         wrdobj.Selection.Range.ListFormat.ListIndent
    78.                          
    79.                         listfiles (mainfolder)
    80.                         wrdobj.Selection.Range.ListFormat.RemoveNumbers wdBulletGallery
    81.                     Else
    82.                         wrdobj.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=wrdobj.ListGalleries(wdBulletGallery).ListTemplates(2)
    83.                         listfiles (mainfolder)
    84.                     End If
    85.                 MsgBox "The files in the folder " & """" & folder1 & """" & " and its subfolders have been listed in the Word document " & """" & "Folder Listing - " & folder1 & ".doc" & """" & " in the " & """" & folder1 & """" & " folder."
    86.                 wrddoc.SaveAs (selectedfolder & "\Folder Listing - " & folder1 & ".doc")
    87.                 wrddoc.Close
    88.                 Set wrddoc = Nothing
    89.                 wrdobj.Quit
    90.                 Set wrdobj = Nothing
    Last edited by poojathakur_13; Oct 4th, 2005 at 12:44 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width