This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Export_to_Word() 'Xuất dữ liệu ra file Word | |
'Khai báo các biến | |
Dim wdapp As Object, wddoc As Object | |
Dim strdocname As String | |
On Error Resume Next | |
'Lấy nội dung vùng dữ liệu bằng cách copy | |
Sheet1.Range("D1:D81").Copy | |
'Mở ứng dụng Word từ VBA | |
Set wdapp = GetObject(, "word.Application") | |
If Err.Number = 429 Then | |
Err.Clear | |
Set wdapp = CreateObject("Word.Application") | |
End If | |
wdapp.Visible = True | |
wdapp.Active | |
'Tạo mới 1 file Word và dán nội dung vào | |
Set wddoc = wdapp.Documents.Add | |
wddoc.Active | |
wddoc.Range.PasteSpecial xlPasteValues | |
'Làm trống các biến để giải phóng bộ nhớ | |
Set wddoc = Nothing | |
Set wdapp = Nothing | |
Application.CutCopyMode = False | |
'Thông báo hoàn thành | |
MsgBox "Done!" | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment