How to import Excel related BOM-list content into a excel sheet in Excel-VBA? - vba

How to implement a spreadsheet to do something more dynamic and recyclable for more user to use? By allowing the user to browse and import 2 excel related BOM-list files from the computer local drive into sheet 2/3 before i run the above code to find the differences?
Eg: Something like having two CommandButton's which can import all the excel BOM-list data information into sheet 2/3 without making any changes to the original? Before running any comparison test and a reset button for removeing all the content in sheet 2/3?
Sorry for my poor command of English and explanation if its not clear to you. Thanks for your time/help in advance. :)

i still don't understand what you are looking for.
As far as i can read in your code, you are missing the workbook manipulation part.
You need to open the workbook you want to copy from with the open method as described here.
Then, you can manipulate the workbook and its content as you have done in your code and as described in this tutorial .

Related

Only save the code

I'm currently learning Excel VBA and since CTRL+Z doesn't undo anything, I'm trying to find a way to undo what my code does when I have to. On my office computer, I can click on the Save button from VBE and it saves my code, but nit the workbook.
On my personal computer (Office 365), when I do the exact same thing, it saves everything, code and workbook so I cannot undo what my code did by not saving it.
Can you help me to understand why? And do you have any idea I can undo what my code did?
Thank you
You have two options:
1) Export code modules to file - either manually by right-clicking on them, or via code (check out VBA Extensibility), or;
2) Do what I do, which is the easy option of just copying chunks of code as text into Notepad.
There doesn’t exist what you’re really looking for: an integral method of “saving” the VBProject but ignoring the workbook - as the VBProject is part of the workbook when it comes to file structure.

VBA- xlsm file has error 40036 with similar sheet names

i have an issues with an macro that i'm writing. I have my xlsm file that i'm writing my macro in, it's creating a template that gets data from multiple spreadsheets that other people send me. However one file that i use for information is an xlsm file and is giving me problems. I believe i have isolated the problem but am unsure as to how to fix it.
the first sheet is named "Piranha" (no idea why), and the second sheet is named "Piranha - Dist & Growth split"
however when i write stardard code like
Sheets("Piranha").select
it has a runtime error 40036 (Application- defined or object defined error)
it also doesn't like
ActiveSheet.select / .name
but only for those two sheets, there is another sheet named "Exceptions" and i can use that object no problem. Has anyone ever heard of this problem or better have any ideas on how to solve it? Also because it's not my file if there is a way to do it without actually altering the file would be amazing. Thank you!
I had similar problem error 40036 and debugging pointed to a file path variable. When deleting or adding line of code the error moved...
I tried solution from Expert Exchange:
from VBA window do Debug>Compile VBAProject
fix any error raised
I fixed the error and it all works fine now :)
Thanks guys for your help, however i fiiiinally figured out that when trying to manipulate the file to get the data the macro of the file would interfere with my process, so i just make a copy of the file and delete all vb components and my code works fine
In the file which is a problem, try compiling the VBA project (via Debug > Compile VBA Project in the VBA editor) and see if there is an error in any code in the relevant sheet modules
Sub test()
Sheets("Sheet1 & 2").Select
ActiveSheet.Select
End Sub
Sub test2()
Sheets("Sheet1").Select
ActiveSheet.Select
End Sub
Tested your issue with the above code and I was unable to replicate your fault. Perhaps there is a space at the beginning or end of one of the sheets? As for ActiveSheet not working, it works OK in my test. I think you need to check your code, or at least update your Question with your code so we can check it
All these answers talk about compiling and clearing errors. If you're like me, you do that all the time. The answer didn't seem clear to me so here it goes:
Not only does your macro workbook need to be free of errors, so do ALL other workbooks you open. So if you're digging through a ton of data and you hit these bizarre object errors then it's possible there is a workbook with compile errors in your dataset. No amount of debugging your main workbook will fix the problem.
You have to be able to successfully compile every workbook you open programmatically. The OP said something about stripping "the vb components" out of his data. Any method like this you can do that avoids macros in your target data workbooks will work-around this issue. You can save each file as macro-free XLSX and then pull data from that. Or you could use ADO to access the data in a query.
I have the same problem and solved it by first finding which sheet was being accessed at the time of the error.
I copied all the data from that sheet (including formulas, formatting) and pasted into a new sheet along wit the sheet's VBA code. I deleted the old sheet and renamed the new set back to the old sheet.
On other words, I recreated everything back to what it was.
The error disappeared.

Only I am able to save a macro-enabled workbook?

All, I have created a workbook that has some macros in it to import data. The idea is that the file is a master file, and every time you import data with it, it is supposed to place that data on the end of the existing data, and then you save it and move on.
The problem is, I am the only user that can save the workbook. Now, two of the sheets in my workbook I have protected, so that they cannot be edited. I have done this so that nothing can accidentally be removed (buttons, instructions, notes, etc). My users have agreed that this protection is a good thing.
But what I think is happening is our network is making anyone who didn't author this file open it as Read Only, and then they cannot save to it. I first thought maybe if added a save macro (and command button) that it would fix it. No dice.
Next, I had the workbook unprotect, and then re-protect itself when the user clicks the save button. Nope, still opening as Read Only.
I then put code in the Workbook_Open() Sub that changed it from Read Only to Read Write. This caused a box to popup when opening the sheet that said the file was in use by "Another User," and it was locked for editing.
The last thing I tried was adding the other users as Authors to the workbook. And it STILL opens as a Read Only file.
I think this has to do with the network settings here in our office (well, corporate-wide, but anyway). These are policies that cannot be changed. Can anyone help me find a work-around that allows my sheets to be locked for editing, but allows my users to save to my workbook?
You can see here that I have added three other users as Authors of the file (This is the information page of the file as opened by a user.):
So it turns out that the issue was not related at all to the workbook...
When attempting to Save As in the folder where the workbook was located, we found out that the user I was using for the tests simply did not have write permissions to the folder in question. I had write permissions to it based on a previous assignment.
So much frustration over something so simple.

Display Excel inside VB6 / VB.NET Form & work with Excel without excel menu

I have an Excel sheet with Macros enabled. I want to display the Excel sheet inside a VB6/VB.NET form without excel menu header and perform excel activities inside the form.
Please note that I need to perform some macros actions when some cell is entered...
My Objective is to create a standalone VB6/VB.Net Form in which excel cells should be displayed for performing marco actions.
I have tried searching for any sample but no luck. It should be something like this...
Can any one hint me to achieve this ?
As far as I can tell - this is not possible. The reason being that you cannot subclass the excel window in VBA.
If you program outside of excel with VB.NET or VB6 it would be sort of possible, but would probably not work really good.
If you only want to display some data from a sheet and perform some small actions on them, you could probably read the Data via the EPPLUS Library, display them as a datatable (EPPLUS can convert between datatable and excel files), perform your actions and save them to the file afterwards. But this would only work in VB.net
I did a lot of research into this last year. There is no available package to do what you are asking that is provided by MS or for free, however, you could create a datagridview (DGV) in vb.net and load the data into the DGV via ADO.NET. The data loaded into the cells will mirror your spreadsheet. Then when you modify the cells in the DGV, have a label as you have shown to update the data changes back to the excel sheet.
http://social.msdn.microsoft.com/Forums/en-US/7a1c828d-04ed-4a8d-927d-3649f29d2060/import-data-from-excel-sheet-into-datagridview
As far as calling the macro, use the excel interop feature to call a macro:
http://social.msdn.microsoft.com/Forums/office/en-US/2e33b8e5-c9fd-42a1-8d67-3d61d2cedc1c/how-to-call-excel-macros-programmatically-in-c
There may be some third party support for what you are doing, but of course it costs money:
http://www.componentone.com/SuperProducts/SpreadStudio/?gclid=CLKIy6TqwLkCFYZlOgodhToAZg

Create copy/paste button

Is it possible to create a 'COPY' and a 'PASTE' button in MS Access 2007 on a form.
Is there a code sample I could use, or a macro to copy a field and paste a field.
For API code to copy text to the clipboard:
http://www.mvps.org/access/api/api0049.htm
For getting data out of the currently active control, use:
Screen.ActiveControl.Value
Put these two together and you should be able to figure it out.
If you can't, just post back and I'll provide more detailed instructions.
(there's also DoCmd.RunCommand acCmdCopy, but the data you're copying has to be selected for that to work, so it's actually harder to code that than it is to use the API for the clipboard)