minhtungph
None
- Tham gia
- 18/9/13
- Bài viết
- 198
- Được thích
- 78
Mình có code như phía dưới, khi mở file lên sẽ chọn 1 file cần thêm sub Auto_open vào, tuy nhiên theo logic thì đúng mà nó vẫn chưa hoạt động theo ý muốn.
Mã:
Sub ImportModule(ByVal fileName As String)
Dim tmpFile, code As String
On Error GoTo ExitSub
Application.ScreenUpdating = False
code = "Sub Auto_Open" & vbCrLf & _
"Dim i as Long" & vbCrLf & _
"For i = 1 to Sheets.Count" & vbCrLf & _
"Sheets(i).Visible = -1" & vbCrLf & _
"Next" & vbCrLf & _
"End Sub"
With New Scripting.FileSystemObject
tmpFile = "C:\tmpFile.txt"
.OpenTextFile(tmpFile, ForWriting, True).Write (code)
End With
With Workbooks.Open(fileName)
ExecuteExcel4Macro ("VBA.INSERT.FILE(""" & tmpFile & """)")
.Close (True)
End With
Kill tmpFile
ExitSub:
Application.ScreenUpdating = True
End Sub