how to import vba Excel code [duplicate] - vba

This question already has answers here:
How To Deploy Word 2010 Macros To Others?
(4 answers)
Closed 8 years ago.
I wrote a code in VBA on a specific excel worksheet (as a macro).
The code works perfectly and now I wish to send it as a script to other people how can I do it? without sending the excel I wrote to macro in, just the script.

Save your workbook as Excel Add-in :)
http://www.ozgrid.com/VBA/excel-add-in-create.htm

The VBE has facilities to export and import files:
In the VBE select the worksheet containing the code and right-click. Select Export to create a file containing the code.
Reverse the process to import a file

Related

Gui for VR from Excel to standalone vba possible? [duplicate]

This question already has answers here:
How can I convert my Excel VBA Macros to EXE File? [closed]
(3 answers)
Is it possible to run a VBA form as a .exe file
(4 answers)
Closed 8 months ago.
Hello I'm trying to realize a shortcut menu to integrate in a VR, so it's basically grabbed from a windows grabber, but It's still in Excel. Is there a way to make this a standalone .exe? Like, it can start and be edited without Excel being open. Because in Excel I have to crop the Excel away to just show the menu/panel
enter image description here

How do I activate an unsaved workbook using VBA?

The goal of my code is to run an online report, copy the data from an exported excel file and paste it back to the main file, and then manipulate the data.
The trouble I'm running into now is copying the data from the exported excel file. The online report exports the excel file as an unsaved "Book1" with one "Sheet1" with the data in it. I cannot seem to activate the exported file so I can copy the sheet.
I've tried
Workbooks("Book1").Activate
As well as using a for loop to iterate through all open workbooks (there are only 2 open workbooks, but the for loop only loops once - telling me that it isn't looping through the unsaved workbook).
Any help would be greatly appreciated. Happy to clarify any questions as well.
Thanks

How to save as excel and vba project for future use?

How can I save as xlsx my project?
I try to do my project in excel with vba but I do know how to save it for future use.
If I save as excel sheet, vba will not be saved to it, I do know how to do that save.
Is there someone who has an idea to this problem?
Please anyone can help me.
xlsx only for data sheet. When you have VBA code in your excel workbook you should save as Excel Macro-Enabled workbook (*.xlsm)
Hello Schadrack Rurangwa**,
There a couple ways to do this.
Altenative One:
save the vba file to ".bas"
1. Click on menu Tools->Macro->Visual Basic Editor
2. This will open Visual Basic Editor
3. In the visual basic editor, select menu File-> Rightclick somewhere in the module and select export file. (save your module ".bas" somewhere).
Next time you start excel and want to use your VBA-Macro, just navigate to:
Tools>Macro->Visual Basic Editor> Rightlclick somewhere in the module and import the ".bas" file.*
Altenative two:
You could save the file Excelfile as "*.xlsm"
(A file with the XLSM file extension is an Excel Macro-Enabled Workbook file)
Macros can be stored in individual workbooks or available for a user in all workbooks opened if they are stored in C:\Users\nnn\AppData\Roaming\Microsoft\Excel\XLSTART\ PERSONAL.XLSB.
For more info see https://support.office.com/en-us/article/create-and-save-all-your-macros-in-a-single-workbook-66c97ab3-11c2-44db-b021-ae005a9bc790

Using Sublime Text or Notepad++ as Editor and Builder for VBA

OK, so I have to learn VBA in my new line of work as we use Excel to more or less anything. The built-in VBA editor in Excel drives me absolutely bonkers - it feels like it's not made for writing code in an efficient way.
I have been using Sublime Text for all coding purposes recent years. There's a plug-in for writing VBA vbScript in Sublime, but I don't understand how to link my Sublime written code to my Excel documents. Say I try to run the following file
Sub test()
Debug.Print "Hello, World"
End Sub
from Sublime Text, I get the following out from the console [Finished in 0.1s], but no printout.
My question is this: does anyone have a solution for how to run VBA in Excel from Sublime Text or Notepad++? I'm still a massive noob in VBA, therefore it would be nice to be able to actually see the effects on the Excel Workbook next to testing the code.
The problem with VBA code and writing it in Sublime is that VBA is embedded into Excel, so you cannot just build the macros you write in Sublime
One solution to this is writing your VBA code and copying-pasting into VBA Editor (mentioned above). This is not manageable when you start working with multiple modules, classes, etc.
Second approach is to use Import/Export functionality of VBA. You can export your modules and classes into *.bas and *.cls files and edit them directly in Sublime Text. For that you can use macros from Ron De Bruin website. Just copy the code into seperate module and it will export all code you have in the currect project into seperate files, which you can edit in Sublime Text. After you make changes in Sublime just import all files back again into VBA editor with the macro. You might want to change the VBA code slightly as well by commenting out
If wkbSource.VBProject.Protection = 1 Then
MsgBox "The VBA in this workbook is protected," & _
"not possible to export the code"
Exit Sub
End If
... otherwise it won't import back to the same spreadsheet.

I need to open a password protected VBA project in an Excel file [duplicate]

This question already has answers here:
Is there a way to crack the password on an Excel VBA Project?
(25 answers)
Closed 8 years ago.
I have an excel file with a VBA Project which is password protected. How can I unlock the file? The person who created this is no longer working and I have to unlock this file to make work easier.
Thanks in advance
Syed
This only works on four letter extension Excel files:
Download HexEdit from this address: http://www.physics.ohio-state.edu/~prewett/hexedit/
Change the extension of the Excel file to ".zip"
Open the file in WinZip
Find and change the name of the file "vbaProject.bin" to "vbaProject.bin1"
Extract the "vbaProject.bin1" file and open it in HexEdit
Search for the phrase "DPB" in the file and change it to "DPx"
Save the fileand remove the "1" at the end of the extension
Import the file back in the .zip file right next to "vbaProject.bin1" file
Delete the "vbaProject.bin1" file, save the .zip file and change the extension back to Excel
Open the Excel file. It will error, but click "OK" or similar