Public ExcelApp As Excel.Application
Public Const Tenfile = "D:\PTH\Khoahoc\Nam2008\Excel_AutoCad.xls"
Sub KhoidongExcel()
On Error Resume Next 'Bo qua loi khi Excel chua mo
'Khi Excel dang mo
Set ExcelApp = GetObject(, "Excel.Application")
'Khi Excel chua mo thi mo
If Err Then
Err.Clear
Set ExcelApp = CreateObject("Excel.Application")
End If
ExcelApp.Visible = True
ExcelApp.Workbooks.Open (Tenfile) 'Mở file dữ liệu Tenfile
AppActivate AutoCAD.Caption
End Sub
Public ExcelApp As Excel.Application
Public Const Tenfile = "D:\PTH\Khoahoc\Nam2008\Excel_AutoCad.xls"
Sub KhoidongExcel()
On Error Resume Next 'Bo qua loi khi Excel chua mo
'Khi Excel dang mo
Set ExcelApp = GetObject(, "Excel.Application")
'Khi Excel chua mo thi mo
If Err Then
Err.Clear
Set ExcelApp = CreateObject("Excel.Application")
End If
ExcelApp.Visible = True
ExcelApp.Workbooks.Open (Tenfile) 'Mở file dữ liệu Tenfile
AppActivate AutoCAD.Caption
End Sub
Dạ. Ý em là như thế này:
+ Em có file Cad gốc
+ Khi mở file Cad lên khi mình click chọn file excel nào thì nó tự lấy đường dẫn ạ ?
Ví dụ: khi file ở trong usb thì nó là:G:\Flile.xls; khi mình copy vào ổ D là: D:\Flile.xls
Như vậy nếu khai báo const thì e không ổn ạ?
Em cám ơn thầy !
Public ExcelApp As Excel.Application Public Const Tenfile = "D:\PTH\Khoahoc\Nam2008\Excel_AutoCad.xls" Sub KhoidongExcel() On Error Resume Next 'Bo qua loi khi Excel chua mo 'Khi Excel dang mo Set ExcelApp = GetObject(, "Excel.Application") 'Khi Excel chua mo thi mo If Err Then Err.Clear Set ExcelApp = CreateObject("Excel.Application") End If ExcelApp.Visible = True ExcelApp.Workbooks.Open (Tenfile) 'Mở file dữ liệu Tenfile
AppActivate AutoCAD.Caption End Sub
Cái đường dẫn "D:\PTH\Khoahoc\Nam2008\Excel_AutoCad.xls"
không phải cố định.Mà khi thực hiện thủ tục thì yêu cầu chọn file Excel, và lấy tên của file vừa mở cập nhật làm đường dẫn luôn
Public ExcelApp As Excel.Application Public Const Tenfile = "D:\PTH\Khoahoc\Nam2008\Excel_AutoCad.xls" Sub KhoidongExcel() On Error Resume Next 'Bo qua loi khi Excel chua mo 'Khi Excel dang mo Set ExcelApp = GetObject(, "Excel.Application") 'Khi Excel chua mo thi mo If Err Then Err.Clear Set ExcelApp = CreateObject("Excel.Application") End If ExcelApp.Visible = True ExcelApp.Workbooks.Open (Tenfile) 'Mở file dữ liệu Tenfile
AppActivate AutoCAD.Caption End Sub
Cái đường dẫn "D:\PTH\Khoahoc\Nam2008\Excel_AutoCad.xls"
không phải cố định.Mà khi thực hiện thủ tục thì yêu cầu chọn file Excel, và lấy tên của file vừa mở cập nhật làm đường dẫn luôn
Public ExcelApp As Excel.Application Public Const Tenfile = "D:\PTH\Khoahoc\Nam2008\Excel_AutoCad.xls" Sub KhoidongExcel() On Error Resume Next 'Bo qua loi khi Excel chua mo 'Khi Excel dang mo Set ExcelApp = GetObject(, "Excel.Application") 'Khi Excel chua mo thi mo If Err Then Err.Clear Set ExcelApp = CreateObject("Excel.Application") End If ExcelApp.Visible = True ExcelApp.Workbooks.Open (Tenfile) 'Mở file dữ liệu Tenfile
AppActivate AutoCAD.Caption End Sub
Cái đường dẫn "D:\PTH\Khoahoc\Nam2008\Excel_AutoCad.xls"
không phải cố định.Mà khi thực hiện thủ tục thì yêu cầu chọn file Excel, và lấy tên của file vừa mở cập nhật làm đường dẫn luôn
Public Tenfile As String
Public Sub OpenFile()
'sample to show how to use FileDialogs
Dim objFile As FileDialogs
Dim strFilter As String
Dim strFileName As String
Set objFile = New FileDialogs
'desc,filter combinations must all be separated with pipe char "|"
strFilter = "All Files (*.*)|*.*|Drawings (*.dwg)|*.dwg"
objFile.OwnerHwnd = ThisDrawing.HWnd 'bind the dialog to the window
objFile.Title = "Open a drawing"
'default dir is CurDir
objFile.StartInDir = "c:\"
objFile.Filter = strFilter
'return a valid filename
strFileName = objFile.ShowOpen
If Not strFileName = vbNullString Then
'use this space to perform operation
MsgBox strFileName
End If
Tenfile = strFileName
Set objFile = Nothing
End Sub