質問編集履歴

1

プログラムコード記載

2017/06/20 01:50

投稿

Goebo
Goebo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -31,3 +31,151 @@
31
31
  参考URL
32
32
 
33
33
  https://www.moug.net/tech/woopr/0110040.html
34
+
35
+
36
+
37
+ Sub RTFファイル結合()
38
+
39
+
40
+
41
+ Dim app As Excel.Application
42
+
43
+ Dim doc_name As String
44
+
45
+
46
+
47
+ pathname = "C:\Users\9A150\Desktop\RTF格納\"
48
+
49
+
50
+
51
+ 'Excelを起動する
52
+
53
+ Set app = CreateObject("Excel.Application")
54
+
55
+
56
+
57
+ 'abc.xlsを開く
58
+
59
+ Dim book As Excel.Workbook
60
+
61
+ Set book = app.Workbooks.Open("C:\Users\9A150\Desktop\RTF格納\bbb.xlsx")
62
+
63
+ app.Visible = True
64
+
65
+
66
+
67
+ 'ファイル名一覧シートを指定
68
+
69
+ Dim sht As Object
70
+
71
+ Set sht = book.Worksheets("Sheet1")
72
+
73
+
74
+
75
+ 'A列を基準に昇順で並べ替えます
76
+
77
+ sht.Range("A2:B10").Sort Key1:=sht.Range("A1"), Order1:=xlAscending, Header:=xlYes
78
+
79
+
80
+
81
+
82
+
83
+ For r = 2 To sht.Cells(sht.Rows.Count, "A").End(xlUp).Row '行を2から最終行まで
84
+
85
+
86
+
87
+ If sht.Cells(r, "A").Value <> "" Then 'A列注目行の値が""でなければ
88
+
89
+
90
+
91
+ 'B列からファイル名を取得する
92
+
93
+ doc_name = sht.Cells(r, "B").Value
94
+
95
+
96
+
97
+ Documents.Open FileName:=pathname & doc_name
98
+
99
+
100
+
101
+ Selection.Fields.Unlink
102
+
103
+
104
+
105
+ 'Selection.Fields.Locked = True
106
+
107
+
108
+
109
+ 'SetAttr ActiveDocument, vbNormal
110
+
111
+
112
+
113
+
114
+
115
+ ActiveDocument.SaveAs2 FileName:=pathname & doc_name, _
116
+
117
+ FileFormat:=wdFormatRTF
118
+
119
+
120
+
121
+ ActiveDocument.Close
122
+
123
+
124
+
125
+
126
+
127
+ ChDir ThisDocument.Path 'Wordファイルと同じフォルダ
128
+
129
+
130
+
131
+ Dim doc As Document
132
+
133
+
134
+
135
+ For Each doc In Documents
136
+
137
+ doc.PageSetup.Orientation = wdOrientLandscape
138
+
139
+ Next doc
140
+
141
+
142
+
143
+ With Selection
144
+
145
+ '.TypeText "ファイル名 = " & doc_name & vbCr
146
+
147
+ '.InsertBreak wdPageBreak
148
+
149
+ .InsertFile doc_name
150
+
151
+ .InsertBreak wdSectionBreakNextPage
152
+
153
+ End With
154
+
155
+
156
+
157
+ End If
158
+
159
+ Next
160
+
161
+
162
+
163
+ 'RTFにて保存
164
+
165
+ ActiveDocument.SaveAs2 FileName:=pathname & "Text.rtf", _
166
+
167
+ FileFormat:=wdFormatRTF
168
+
169
+ ActiveDocument.Close
170
+
171
+
172
+
173
+ book.Close
174
+
175
+
176
+
177
+ Call PDFに変換
178
+
179
+
180
+
181
+ End Sub