麻辣家族討論版版's Archiver

dou10801 發表於 2021-10-27 08:59

匯入txt檔後,如何分頁.

匯入txt檔後,如何每20行作分頁(分辨[A]就分頁),感恩.

samwang 發表於 2021-10-27 11:04

[i=s] 本帖最後由 samwang 於 2021-10-27 11:16 編輯 [/i]

[quote]匯入txt檔後,如何每20行作分頁(分辨[A]就分頁),感恩.
[size=2][color=#999999]dou10801 發表於 2021-10-27 08:59[/color] [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=117432&ptid=23445][img]http://forum.twbts.com/images/common/back.gif[/img][/url][/size][/quote]

新增如下紅字部分,請測試看看,謝謝

Sub 按鈕1_Click()
[color=Red]Dim Arr, Brr(1 To 20, 1 To 1), i&, n%
[/color]fs = ThisWorkbook.Path & "\sun03.txt"
Open fs For Input As #1
i = 1   '從第一格開始匯入
Do While Not EOF(1)    ' 執行迴圈直到檔尾為止。
    Line Input #1, TextLine
    Cells(i, 1) = TextLine
    i = i + 1
Loop
Close #1

[color=Red]Arr = Range([a1], [a65536].End(3))
For i = 1 To UBound(Arr)
    n = n + 1: Brr(n, 1) = Arr(i, 1)
    If n = 20 Or i = UBound(Arr) Then
        With Sheets.Add(after:=Sheets(Sheets.Count))
            .[a1].Resize(20) = Brr
        End With
        n = 0: Erase Brr
    End If
Next
[/color]End Sub

dou10801 發表於 2021-10-27 12:17

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=117433&ptid=23445]2#[/url] [i]samwang[/i] [/b]感謝samwang回覆,可否產生在同一個工作表,預覽列印,翻頁時[A]在每頁的第一位,謝謝.

samwang 發表於 2021-10-27 13:35

[quote]回復  samwang 感謝samwang回覆,可否產生在同一個工作表,預覽列印,翻頁時[A]在每頁的第一位,謝謝.
[size=2][color=#999999]dou10801 發表於 2021-10-27 12:17[/color] [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=117434&ptid=23445][img]http://forum.twbts.com/images/common/back.gif[/img][/url][/size][/quote]

如附件請測試看看,謝謝

dou10801 發表於 2021-10-27 13:41

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=117435&ptid=23445]4#[/url] [i]samwang[/i] [/b]感謝感謝.
可否加註解,收下慢慢學習.
If Arr(i, 1) = "[A]" Then
        Rows(i).PageBreak = xlPageBreakManual
        Columns("i").PageBreak = xlPageBreakManual
    End If

samwang 發表於 2021-10-27 15:26

[quote]回復  samwang 感謝感謝.
可否加註解,收下慢慢學習.
If Arr(i, 1) = "[A]" Then
        Rows(i).PageBr ...
[size=2][color=#999999]dou10801 發表於 2021-10-27 13:41[/color] [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=117436&ptid=23445][img]http://forum.twbts.com/images/common/back.gif[/img][/url][/size][/quote]

PageBreak用法,可參考如下,謝謝
[url]https://docs.microsoft.com/zh-tw/office/vba/api/excel.range.pagebreak[/url]

准提部林 發表於 2021-10-29 15:28

[i=s] 本帖最後由 准提部林 於 2021-10-29 15:32 編輯 [/i]

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=117436&ptid=23445]5#[/url] [i]dou10801[/i] [/b]

多善用vbe內建說明檔:
1)選取要查詢的文字,按"複製"//按上方"?"快速說明鈕, 貼上文字
[attach]34299[/attach]

2)點按關鍵字
[attach]34300[/attach]

3)點按"範例"及"適用於"都有進一步說明
[attach]34301[/attach]

凡事自求多助吧!

dou10801 發表於 2021-11-1 08:10

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=117480&ptid=23445]7#[/url] [i]准提部林[/i] [/b]
感謝准提部林大大指點,這個對初者受益良多.

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供