Home > Software engineering >  Call DLL do to deal with vba, excel file
Call DLL do to deal with vba, excel file

Time:10-25

Pole "link: http://www.officefans.net/cdb/viewthread.php? Tid=230741 & amp; Highlight=
Because CSDN can't upload attachments, so attached to weigh in the attachment,

Because you need to do to excel vba by loading the DLL file encapsulation, studied the http://www.officefans.net/cdb/viewthread.php? Tid=101939 after the contents of this post, you try to do the
My demand is in a particular excel (for example, d: \ sample. XLS) opens automatically open call DLL DLL packaging forms, and then click on the button on the form after msgbox sheets (" sheet1 ") cells (1, 1). The value, is very simple, but encountered a problem


Need to set up open the excel object in vb, use the following similar statements
Dim ExcelApp As New Excel. Application
Dim ExcelWorkBook As Excel. The Workbook
Dim ExcelWorksheet As Excel. The Worksheet
The Set ExcelWorkBook=ExcelApp. Workbooks. Open (" d: \ sample. XLS ") 'Open workbook


But the problem is that the equivalent of a new process of excel, and then opens the d: \ sample.xls files for subsequent processing, but I demand is not the new excel process, also do not need to open again d: \ sample like this problem, but just in the excel file, the d: \ sample like this file, so, don't know how to write code, and the current in the excel file to load into the DLL ExcelApp object, thus for subsequent processing,


Test. Zip (20.98 KB) accessories: report. The DLL is compiled to program, and then open the sample. The XLS calls the DLL files, thus opened the form form, and then click on the form button, start the DLL encapsulation process,
One thing to note: sample references in the report. The DLL file, place the absolute path because each person is different, so may need you to quote a can,


We help prawns! Thank you very much!!!!!

CodePudding user response:

Dim ExcelApp As New Excel. Application
Dim ExcelWorkBook As Excel. The Workbook
Dim ExcelWorksheet As Excel. The Worksheet
If ExcelApp. Workbooks. Count & gt; 0 Then
Set ExcelWorkBook=ExcelApp ActiveWorkbook 'if the current work, this to the current work operation
The Else
The Set ExcelWorkBook=ExcelApp. Workbooks. Open (" d: \ sample. XLS ") 'if the current work without this, it is Open work
End If

CodePudding user response:

As you open, will not cause a "loop"?
(fortunately Excel will ask whether or not to open, otherwise really into dead circulation,)

You can try this:
 'Set ExcelWorkBook=ExcelApp. Workbooks. Open (" d: \ sample. XLS ")' Open workbook 
The Set ExcelWorkBook=ExcelApp. ThisWorkbook


To preach the attachment, you can upload attachments on the first place:
http://access911.net/csdn
Then put your link address of the attachment is posted,
As you said in your ZhuTie the original connection, others are not necessarily can download (must have the BBS account, login to download),

CodePudding user response:

Please let vba in excel in article 2000 of data in a sheet to the oracle bulk insert data have what good way? Cycle is too slow to feel, you have what good method? thank you

CodePudding user response:

Open VB, create an add-in project:
The designer code:
 
Public WithEvents XlApp As Excel. Application

Private Sub AddinInstance_OnConnection (ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects. Ext_ConnectMode, ByVal AddInInst As Object, the custom () As the Variant)
The Set XlApp=Application
End Sub

Private Sub AddinInstance_OnDisconnection (ByVal RemoveMode As AddInDesignerObjects. Ext_DisconnectMode, custom () As the Variant)
The Set XlApp=Nothing
End Sub

Private Sub XlApp_WorkbookOpen (ByVal Wb As Excel. The Workbook)
If LCase (Wb) FullName)="d: \ sample. XLS" Then
The Set My_Wb=Wb
FrmAddIn. Show 0
End the If
End Sub

Form to add a button named: Command1.
The form code:
 
Private Sub Command1_Click ()
MsgBox My_Wb. Sheets (" sheet1 ") cells (1, 1). The Value
End Sub

Module code:
 

. Public My_Wb As Excel Workbook



The diagram below:


CodePudding user response:

reference 4 floor crazy0qwer response:
open VB, to create an add-in project:
The designer code:
 
Public WithEvents XlApp As Excel. Application

Private Sub AddinInstance_OnConnection (ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects. Ext_ConnectMode, ByVal AddInInst As Object, the custom () As the Variant)
The Set XlApp=Application
End Sub

Private Sub AddinInstance_OnDisconnection (ByVal RemoveMode As AddInDesignerObjects. Ext_DisconnectMode, custom () As the Variant)
The Set XlApp=Nothing
End Sub

Private Sub XlApp_WorkbookOpen (ByVal Wb As Excel. The Workbook)
If LCase (Wb) FullName)="d: \ sample. XLS" Then
The Set My_Wb=Wb
FrmAddIn. Show 0
End the If
End Sub

Form to add a button named: Command1.
The form code:
 
Private Sub Command1_Click ()
MsgBox My_Wb. Sheets (" sheet1 ") cells (1, 1). The Value
End Sub

Module code:
 

. Public My_Wb As Excel Workbook



The diagram below:


Hello, sorry now just to see this post at that time, middle busy doing other things for a long time,
Very thank you for your detailed reply, I according to the test, you said in the generated MyAddIn. DLL in the process, the module of Public My_Wb As Excel. An error on the Workbook this sentence: "compiler error: user-defined types undefined"

Don't know what's the problem? Thank you so much!

CodePudding user response:

refer to the second floor Chen8013 response:
open like that, you will not cause a "loop"?
(fortunately Excel will ask whether or not to open, otherwise really into dead circulation,)

You can try this:
 'Set ExcelWorkBook=ExcelApp. Workbooks. Open (" d: \ sample. XLS ")' Open workbook 
The Set ExcelWorkBook=ExcelApp. ThisWorkbook


To preach the attachment, you can upload attachments on the first place:
http://access911.net/csdn
Then put your link address of the attachment is posted,
As you said in your ZhuTie the original connection, others are not necessarily can download (must have the BBS account, login to download),


Very thank you for your remind, the upload link is very useful!
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related