Chạy add in bị lỗi compile error cant find library
Khi tạo 1 file VBA, bình thường chỉ là 1 file XLA không có các wookbook đi kèm. Vậy có cách nào tạo 1 file VBA có chứa cả các wookbook không, nếu tạo được thì có cách nào dấu các wookbook đó khi chạy file XLA không Bình_OverACOver Abnormal / Crazy
Ui trời ơi! bạn hỏi gì tui chả hiểu gì hết vậy! cái gì mà file VBA, file XLA không có các workbook đi kèm, dấu các workbook khi chay file XLA???? Rối quá. Tui xin giải thích giúp bạn một số khái niệm theo cách hiểu của tui về những cái này nhé: 1. VBA là gi?: VBA là ngôn ngữ Visual Basic for Application có nghĩa là ngôn ngữ dành cho cách trình ứng dụng mà cụ thể là các trình ứng dụng của MS Office. Do đó khi nói lập trình VBA cho Excel thì không gọi là kết hợp vì bản chất của nó là dành cho nhau. 2. Cấu trúc một file Excel: một file Excel hay còn gọi là một workbook (mỗi file chỉ có một workbook, không có các workbook). File Excel gồm các phần sau:
3. File XLA là một công cụ gắn thêm vào Excel để hổ trợ người dùng. File XLA không cần có các worksheet. Vì người ta không thao tác trên các đối tượng của Excel trong file này mà chỉ ứng dụng những kết quả từ các phần hổ trợ của file này. 4. Tạo file XLA. Chỉ cần save as chọn file type là Microsoft Office Excel Add-in thì một file excel bình thường biến thành file XLA. File XLA mà không có các phần hổ trợ thì là file bỏ đi. File XLA không cần được thao tác trên các worksheet của nó nên các worksheet tự động được dấu đi (nhưng dử liệu, công thức của nó thì hình như vẩn còn trong đó). Do đó: Khi lưu một file Excel thành file XLA thì người ta bỏ tất cả các worksheet và chỉ để lại một worksheet trắng. levanduyetWelcome
To: thonon, Bạn nên phân biệt file *.xla và VBA! _*.xla file là một file add-in của Excel. _ VBA là viết tắt của chữ Visual Basic for Application, là một ngôn ngữ lập trình hổ trợ cho bộ Microsoft Office. Câu hỏi của bạn không rõ. Bạn nên xem lại và đặt câu trả lời thích hợp. Có như vậy các bạn khác mới có thể giúp bạn được. Chúc bạn khỏe, Lê Văn Duyệt thononGuest
Dowload file XLA Xin lỗi vì câu hỏi đấy, Hãy dowload file XLA này về và sử dụng thêm tool AOPR bạn sẽ hiểu lại câu hỏi của tớ. mail: [email protected] Pass: 29l52455 levanduyetWelcome
To: thonon, Tôi đã mở file add-in này nhưng có gì đặc biệt đâu! Cũng như các file bình thường khác mà thôi. Không có hiện tượng như bạn nói?! Thân, Lê Văn Duyệt Tran ChauGuest
Theo I biết thì Corel Draw, Autocad.. co dung VBA SA_DQThành viên Cố vấn - Webketoan Mentors
Điều khiển các macro từ phần mềm VB khác? Cho hỏi Có thể Từ Trong MS ACCESS lập đoạn mã để điều khiển các macro đã viết trong EXCEL được không các bác?! Le Minh HoangGuest
VB trong office! Theo minh duoc biet thi dieu ban hoi rat kho thuc hien boi giua moi truong lam viec cua Excel va Access co su khac nhau hon nua neu co lam duoc thi ban phai chay dong thoi hai moi truong ma dieu nay la bat cap . Ban chi co the viet cac ham trong moi truong excel hoac Access va su dung chi trong moi truong noi tai cua no ma thoi ! TuanktcdcnLão già ham vui
Để điều chỉnh sửa nội dung của Macro trong EXCEL từ ACCESS thì không được. nhưng nếu các Macro được viết trên Macrosheet4.0 thì OK nhưng loại Macro này không còn phát triển nữa. Nếu bạn muốn dùng các thủ tục hay hàm cho cả EXCEL và ACCESS thì dùng DLL. adam_tranGuitar inspiration
Hỏi thêm 1 chút về DLL Nếu bạn muốn dùng các thủ tục hay hàm cho cả EXCEL và ACCESS thì dùng DLL. Thuật ngữ DLL (Dynamic Library Link) thì tớ biết, và cũng biết công dụng của nó. Nhưng không biết VBA trong Excel có xuất ra DLL được không, muốn xuất ra thì phải làm như thế nào và muốn sử dụng DLL đó thì phải làm thế nào. Tớ sử dụng nhiều Add-In khác nhau, mỗi lần có cái mới nếu để nguyên thì Excel mở nhiều *.XLA quá, copy vào 1 cái *.xla thì phiền, với lại hay bị các phần mềm chống virus xóa mất macro. tranxuanthienGuest
Theo tôi biết thì VBA Excel không tạo ra được file DLL nhưng thường xuyên dùng nó khi làm việc với các thành phần của Excel cũng như của các chương trình khác. Bạn có để riêng xla hay copy chung mã nguồn trên cùng một xla thì chương trình quét virus (D32, Bkav) vẫn cứ "tiêu diệt" như thường khi bạn ra lệnh cho chúng, do đó tội gì mà không cop chung vào một xla cho đỡ lòng thòng, rối rắm (Theo ý kiến cá nhân của tôi thì bạn đừng nên dùng Bkav vì điều này và cũng vì bản thân nó dễ bị vô hiệu hoá bởi virus) TuanktcdcnLão già ham vui
EXCEL không tạo ra được DLL mà chỉ dùng nó mà thôi. Ngoài XLA thì còn có 2 loại file mà EXCEL tích hợp được là *.XLL và *.DLL. Với DLL bạn có thể dùng VB, C++, VC++, Delphi để tạo ra chúng. XLL bạn phải dùng VC++ để tạo. Nếu bạn đã quen với VBA thì tạo DLL trên VB6.0 là thuận tiện nhất, tuy nhiên khi biên dịch thành DLL bạn cần thêm một thư viện đi cùng là MSVBVM6.0.DLL nhưng nếu máy cài HĐH WINXP thì không cần file thư viện này. Nếu bạn dùng C++,VC++, Delphi thì tuyệt vời nhất vì nó không cần kèm theo một thư viện nào khác và chúng ta có thể khai báo chúng như khai báo với User32.DLL, Kenerl32.DLL,...của HĐH. Tuy nhiên các ngôn ngữ trên học không đơn giản. SA_DQThành viên Cố vấn - Webketoan Mentors
Ok/no? Để điều chỉnh sửa nội dung của Macro trong EXCEL từ ACCESS thì không được. nhưng nếu các Macro được viết trên Macrosheet4.0 thì OK nhưng loại Macro này không còn phát triển nữa. Nếu bạn muốn dùng các thủ tục hay hàm cho cả EXCEL và ACCESS thì dùng DLL. Tôi thấy bên diễn đàn VNN người ta bảo được đấy? Nhưng không hiểu lắm mới qua đây hỏi vậy mà! Người ta bảo phải khai báo biến đối tượng excel như Sheets, Macro .. . từ Access. Khó quá & nan giải! TuanktcdcnLão già ham vui
Nếu chỉ để chạy thôi thì không có gì nhưng nếu sửa được Macro trong các Module ở VBA thì tôi chưa làm được mà cũng chưa thấy ai làm được, còn VNN tôi cũng không thấy ai? Nếu mà sửa được các Macro trong các Module ở VBA thì cũng có nghĩa là phá được hay xem được code trong VBA. Như vậy Password trong VBA để làm gì? I nghĩ muốn làm được chắc phải hỏi Microsoft. workmanGuest
Làm được đấy. Thực ra mình không cần phải thay đổi macro trong excel đâu. Thông thường người ta run trực tiếp trên Access thôi. Đây là đoạn mã tôi làm trên Access để run các lệnh trong excel. Các bạn làm thử nhé. Function ViduExcel() Dim XLS As New Excel.Application ThuMuc = CurrentProject.Path MoFile = "testing.xls" XLS.Workbooks.Open Filename:=WorkDir & MoFile End function các bạn thử nhé. Nếu bạn nào muốn excel hoặc access tự động gửi thư (email) thì báo cho tôi biết. Tôi còn 1 đoạn mã để gửi email. StonyHeartedManGuest
Function ViduExcel() Dim XLS As New Excel.Application ThuMuc = CurrentProject.Path MoFile = "testing.xls" XLS.Workbooks.Open Filename:=WorkDir & MoFile End function các bạn thử nhé. Nếu bạn nào muốn excel hoặc access tự động gửi thư (email) thì báo cho tôi biết. Tôi còn 1 đoạn mã để gửi email.Chú ý, trong lập trình cố gẳng tránh dùng Early-Bind Object như trên, Hãy dùng Late-Bind Object với CreateObject. Chú ý: dùng xong object thì phải Release resource (nếu dùng VB, hay VBA thì viết là Set objYourObject = Nothing hoặc If Not objYourObject IsNothing Then Set objYourObject = Nothing (Có thể Close Object (tùy object) trước khi giải phóng tài nguyên). Bài viết này phù hợp với CLB Programing nhỉ :biggrin: PS: ở ví dụ trên, Excel đóng vai trò OLE Application Server (Để cho các Client App có thể tao được Object) :biggrin: workmanGuest
Bài viết này phù hợp với CLB Programing nhỉ :biggrin: PS: ở ví dụ trên, Excel đóng vai trò OLE Application Server (Để cho các Client App có thể tao được Object) :biggrin:Gặp cao thủ rồi :0frown: . Thực ra tôi cũng chỉ copy lại thôi, chứ không rành lắm. Thank you bạn đã chỉ giáo. Sẵn đây bạn cho biết luôn Early-Bind Object và Late-Bind Object là cái chi vậy. Xin lỗi hỏi hơi bị ngu, nhưng tôi là dân kế toán mà. thanhvo31Guest
He, ông bạn ơi ông thử tiêu hoá cái này thử xem: Use Early Binding Wherever Possible Whenever you declare a variable As Object, VBA doesn't know anything about it until runtime. Every time you call a property or method of the object, VBA has to check whether the method exists, check its parameters and confirm your code can call it. All of that takes time and should be avoided by giving all your variables specific types. If you are using As Object to be able to call the same property (for example, Name) on a number of your own classes, you should implement a custom interface in those classes instead. *********** cái này nữa, xin bác thông cảm vì tôi kém cái món Anh văn lắm nên sợ dịch không hết nghĩa Early Binding vs. Late Binding The distinction between early binding and late binding is widely misunderstood and often confused with how an object is created. The only thing that affects whether an object is early bound or late bound is how the object variable holding the reference to the object was declared. Variables declared as a specific object data type are always early bound. Variables declared with the Object or Variant data type are always late bound. Listing 3-12 shows an example of a late bound reference, and Listing 3-13 shows an example of an early bound reference. Listing 3-12. A Late Bound Reference to an ADO Connection Object Dim objConnection As Object ' It doesn't matter how you create the object, it's still ' late bound due to the As Object variable declaration. Set objConnection = New ADODB.Connection Set objConnection = CreateObject("ADODB.Connection") Listing 3-13. An Early Bound Reference to an ADO Connection Object Dim cnConnection As ADODB.Connection ' It doesn't matter how you create the object, it's still early ' bound due to the data type used in the variable declaration. Set cnConnection = New ADODB.Connection Set cnConnection = CreateObject("ADODB.Connection") Note that to use early binding with objects that are outside the Excel object model you must set a reference to the appropriate object library using the Tools > References menu in the Visual Basic Editor. For example, to create early bound variables referencing ADO objects, you must set a reference to the Microsoft ActiveX Data Objects 2.x Library, where x is the version of ADO you intend to use. You should use early bound object variables wherever possible. Early bound object variables provide the following advantages over late bound variables: Improved performance When you use an object variable whose data type is known to VBA at compile time, VBA can look up the memory locations of all property and method calls you use with this object and store them with your code. At runtime, when VBA encounters one of these early bound property or method calls, it simply executes the code located at the stored location. (This is a bit of an oversimplification. What VBA actually stores is a numeric offset to the code to be executed from a known starting point in memory, which is the beginning of a structure called the object's VTable.) When you use a late bound object variable, VBA has no way of knowing in advance what type of object the variable will contain. Therefore, it cannot optimize any property or method calls at compile time. This means that each time VBA encounters a late bound property or method call at runtime, it must query the variable to determine what kind of object it holds, look up the name of the property or method being executed to determine where in memory it is located and then execute the code located at that memory address. This process is significantly slower than an early bound call. Strict type checking In the late bound example in Listing 3-12, if you accidentally set your object variable to reference an ADO Command object instead of a Connection object, VBA would not complain. You would only discover you had a problem downstream in your code when you tried to use a method or property not supported by the Command object. With early binding, VBA will immediately detect that you are trying to assign the wrong type of object reference to your object variable and notify you with a "Type mismatch" error. Incorrect property and method calls can be detected even earlier, before the code is ever run. VBA will attempt to look up the name of the property or method being called from within the appropriate object library at compile time and throw an error if the name cannot be located. IntelliSense availability Early bound object variables make for much easier programming as well. Because VBA knows exactly what type of object a variable represents, it can parse the appropriate object library and provide a drop-down list of all available properties and methods for the object as soon as you type a dot operator after the variable's name. As you might expect, in some cases you need to use late binding rather than early binding. The two most common reasons for using late binding rather than early binding are as follows: When a newer version of an application's object library has broken compatibility with an earlier version. This is an all too common situation. If you set a reference to the later version of the application's object library in your application and then attempt to run it on a computer that has the earlier version, you will get an immediate compile time error "Can't find project or library," and the reference on the target machine will be prefixed with MISSING. The most insidious thing about this error is that the line of code flagged as being the source of the error will often have nothing to do with the object library actually causing the problem. If you need to use objects from an application that exhibits this problem and you want to support users with any version of the application, you need to use late binding for all variables referencing objects from the application. If you are creating new objects, you also need to use the CreateObject function with the version-independent ProgID of the object you want to create, rather than the = New ObjectName syntax. When you want to use an application that you cannot be sure will exist on the user's computer and that you cannot install yourself. In this case, you need to use late binding to avoid the compile time error that would immediately result from attempting to run an application that referenced an object library that did not exist on the user's computer. Your application can then check for the existence of the object library in question and exit gracefully if that library is not installed on the user's computer. TIP Even if you will eventually use late binding in your code, early binding offers such a great increase in productivity while coding that you should write and test the application using early binding. Convert your code to late binding only for the final round of testing and distribution. ++++ trích trong cuốn: Professional Excel Development: The Definitive Guide to Developing Applications Using Microsoft® Excel and VBA® By Stephen Bullen, Rob Bovey, John Green Mà hình như cuốn này có trong thư viện Gmail đó workmanGuest
Cám ơn bác nhiều nhé. Bác vất vả quá. Món này cao siêu và khó tiêu thật. Mà tiếng Anh của tôi chỉ giới hạn thôi. Cuốn Excel VBA programing for Dummies của bác Duyệt coi bộ phù hợp hơn với trình độ vỡ lòng của tôi. |