回答編集履歴

1

改良版

2020/01/10 08:28

投稿

ttyp03
ttyp03

スコア16998

test CHANGED
@@ -59,3 +59,69 @@
59
59
 
60
60
 
61
61
  ```
62
+
63
+
64
+
65
+ ---
66
+
67
+ 改良版です。
68
+
69
+ あまり変わっていませんが、文字コードは明確に指定しないといけなくなってしまいました。
70
+
71
+ ```VBA
72
+
73
+ Sub PasteText(fn As String, cp As Variant, dst As Range)
74
+
75
+ Application.ScreenUpdating = False
76
+
77
+ Dim wb As Workbook
78
+
79
+ Workbooks.OpenText Filename:=fn, Origin:=cp, FieldInfo:=Array(1, xlTextFormat)
80
+
81
+ Set wb = ActiveWorkbook
82
+
83
+ wb.Worksheets(1).Cells(1, 1).CurrentRegion.Copy
84
+
85
+ dst.PasteSpecial xlPasteValues
86
+
87
+ wb.Close
88
+
89
+ Application.ScreenUpdating = True
90
+
91
+ End Sub
92
+
93
+
94
+
95
+ Sub Load_Souce()
96
+
97
+ Dim txtName As String
98
+
99
+
100
+
101
+ ' 1つ目のファイル(ANSI)
102
+
103
+ txtName = Application.GetOpenFilename("テキストファイル,*.txt")
104
+
105
+ If txtName <> "False" Then
106
+
107
+ Call PasteText(txtName, 932, Range("A11"))
108
+
109
+ End If
110
+
111
+
112
+
113
+ ' 2つ目のファイル(UTF8)
114
+
115
+ txtName = Application.GetOpenFilename("テキストファイル,*.txt")
116
+
117
+ If txtName <> "False" Then
118
+
119
+ Call PasteText(txtName, 65001, Range("B11"))
120
+
121
+ End If
122
+
123
+ End Sub
124
+
125
+
126
+
127
+ ```