ngoclinh2501 > 03-07-13, 07:47 PM
paulsteigel > 04-07-13, 09:24 AM
Sub OpenInsertRow()
'
' OpenInsertRow Macro
' For Inserting a row in an Excel File
'
'
Workbooks.Open Filename:="E:\My Documents\NHóm 4 CP.xls"
Rows("3:3").Select
Selection.Insert Shift:=xlDown
Range("A4").Select
ActiveWindow.Close
End Sub
Option Compare Database
Sub OpenInsertRow()
'
' OpenInsertRow Macro
' For Inserting a row in an Excel File
'
'
' Doan code de ket noi voi Excel
Dim ExApp As Object
Dim ExBook As Object
Dim ExSheet As Object
' Khoi tao mot so hang so lien quan cua Excel de tranh loi
Const xlDown = -4121
' Khoi tao mot Doi tuong Excel (Excel Application Instance)
Set ExApp = CreateObject("Excel.Application")
' Hien thi cua so Excel
ExApp.Visible = True
' Mo tai lieu
Set ExBook = ExApp.Workbooks.Open(Filename:="E:\My Documents\NHóm 4 CP.xls")
' Gan Sheet can chen dong voi Sheet1
Set ExSheet = ExBook.Sheets("Sheet1")
With ExSheet
' Chen them dong vao dong so 3
.Rows("3:3").Insert Shift:=xlDown
End With
' Dong Worbkook
ExBook.Close True
' Giai phong cac bien
Set ExSheet = Nothing
Set ExBook = Nothing
Set ExApp = Nothing
End Sub
Xuân Thanh > 04-07-13, 04:02 PM
Option Compare Database
Option Explicit
Sub InsertRows()
' Dinh nghia bien Excel,ten file Excel can mo, Workbook, Worksheet
Dim Ex As Excel.Application
Dim Wb As Workbook
Dim Ws As Worksheet
Dim FileEx As String
FileEx = "D:\Excel\abc.xls"
'FileEx = CurrentProject.Path & "\abc.xls"
' Mo file Excel
Set Ex = New Excel.Application
Ex.Visible = True
Set Wb = Ex.Workbooks.Open(FileEx)
Set Ws = Wb.Worksheets("ABC")
' Chen them mot dong duoi dong so 3
Ws.Range("A3").EntireRow.Insert Shift:=xlDown
' Giai phong bien
Set Ws = Nothing: Set Wb = Nothing: Set Ex = Nothing
End Sub