Macro to upload all the TXT files at once

jevi

Active Member
Joined
Apr 13, 2010
Messages
339
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have this macro which a collegue of mine did but I have to upload one by one the txt written the name in the box, but I would like that I can upload all the files TXT that are in the folder in the word document with this macro.

So the modification that I need is to upload the TXT files all at once and not one by one. Is there a way to do it?

Thank you,

SQL:
Sub ImportaFileFcFc()
  Dim file, riga, fc, riga1 As String
  Dim count, maxRow As Integer
  
  count = 0
  maxRow = 60      ' Max Row per page
  
  file = InputBox("Nome File", "Nome file")
  If (file <> "") Then
    If InStr(1, file, ":", vbTextCompare) > 0 Then
        Open file For Input As #1
    Else
        Open ActiveDocument.Path & "\" & file For Input As #1
    End If
  Else
    Return
  End If
    
    With ActiveDocument.Paragraphs(1)
    .LineSpacingRule = wdLineSpaceExactly
    .LineSpacing = 11
    End With
    
  Do While Not EOF(1)
     Line Input #1, riga
     fc = Mid(riga, 1, 1)
     riga1 = Mid(riga, 2, Len(riga))
     
    ' VALORI PER *FCFC
    ' Blank = Avanza stampa di 1 rigo
    ' Zero  = Avanza stampa di 2 righi
    ' Meno = Avanza stampa di 3 righi
    ' Più     = Avanza stampa di zero righe
    ' Uno   = Salto a riga uno
     
     Select Case fc
      Case " "
        count = count + 1
        Selection.TypeText (vbCr)
        Selection.TypeText (riga1)
      Case "0"
        count = count + 2
        Selection.TypeText (vbCr)
        Selection.TypeText (vbCr)
        Selection.TypeText (riga1)
      Case "-"
        count = count + 3
        Selection.TypeText (vbCr)
        Selection.TypeText (vbCr)
        Selection.TypeText (vbCr)
        Selection.TypeText (riga1)
      Case "+"
        count = count + 0
        Selection.TypeText (riga1)
      Case "1"
        count = 1
        Selection.InsertBreak Type:=wdPageBreak
        'Selection.TypeText (vbCr)
        Selection.TypeText (riga1)
     End Select
     
  Loop

  Close #1    ' Chiude il file.

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,223,979
Messages
6,175,761
Members
452,668
Latest member
mrider123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top