• Print one sheet of labels for all files in a dir?

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Print one sheet of labels for all files in a dir?

    • This topic has 1 reply, 2 voices, and was last updated 24 years ago.
    Author
    Topic
    #1769281

    Hello.
    I need to print a sheet of address labels for all the files in a directory.
    I.e., I have 12 Word docs in a directory, each a letter, each addressed to a different receipient. Instead of individually opening each letter and printing an envelope separately, I’d like to be able to run a script which would pass through all the documents, extract each address and print all 12 on one label sheet.
    Is this possible?
    Thank you.

    Viewing 0 reply threads
    Author
    Replies
    • #1782867

      Hi
      The following should loop thru the directory open/close each of the documents. No guarantees though.
      ============================================
      sub loopingLabels
      Dim FS
      Dim i As Integer
      Set FS = Application.FileSearch
      Dim strFileName()
      Application.ScreenUpdating = False

      With FS.PropertyTests
      .Add Name:=”Files of Type”, _
      Condition:=msoConditionFileTypeWordDocuments, _
      Connector:=msoConnectorOr
      End With

      With FS
      ‘ set you path here in the lookIn statement
      .LookIn = “C:DataWordDocs”
      ReDim strFileName(FS.FoundFiles.Count)
      MsgBox (FS.FoundFiles.Count)’optional line

      If .Execute(SortBy:=msoSortByFileName, _
      SortOrder:=msoSortOrderAscending) > 0 Then
      For i = 1 To .FoundFiles.Count
      strFileName(i) = .FoundFiles(i)
      Documents.Open (strFileName(i))
      ‘———————————————–
      ‘do something here to make label ??
      ‘———————————————–
      ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
      Next i
      Else
      MsgBox “There were no files found.”
      End If
      End With
      Set FS = Nothing
      End Sub
      ================================================
      I hope this is a starter, sorry about the do something here to make labels.
      It is all smoke & mirrors !!

      Cheers
      G

    Viewing 0 reply threads
    Reply To: Print one sheet of labels for all files in a dir?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: