last day (15 days later) » 

10:45 AM
0
Q: Create a loop that import bas files in every .xlsm files from a folder?

salifgotemThe actual code : Sub throwaway() Dim xStrPath As String Dim xFileDialog As FileDialog Dim xFile As String Dim strFolder As String: strFolder = "K:\blabla" & "\" Dim strTempFile As String: strTempFile = strFolder & "aaOWB.bas" Set xFileDialog = Application.FileDi...

 
1. You must open each such workbook. 2. What do you want doing by previously exporting the module? You should remove it, if exists. Or if you need to keep it for I do not know what reason, choose a different folder where to export it. 3. Using the full path for setting a VBProject is wrong. You should use the workbook name. 4. Comment On Error Resume Next! This will only not let you see the errors raised when try fancy things...
 
@VincentG 4- You mean when i use VBProject it only looks for opened workbooks so i need to open them before right ?
@FaneDuru 3- But the file where my bas file come from is on my computer and I want to export my bas file into workbooks that be on my server… Wouldn't be a problem, you think?
I made an edit taking each of your suggestions but i got error 438 there Application.VBE.VBProject(xStrPath & "\" & xFile).Unprotect Password:=700
 
"import bas files in every .xlsm files from a folder" meant for me that the bass file(s) is/are already in the respective folder... If not, you did not well explain in words what you try doing. So, do you want exporting a module (named "aaOWB") and then import it in the workbooks from "xStrPath"? I can see now a different code than in the moment I answered. I mean only once (correct) exporting it and then trying to import and saving. I told you in my comment that VBProject(xStrPath & "\" & xFile) does not make any sense.
What you try doing by Application.VBE.VBProject(xStrPath & "\" & xFile).Unprotect Password:=700? What protection do you try removing? A VBProject object does not have such a property! Anyhow, you should set a workbook VBProject as Workbooks(xFile).VbProject. And using as Workbooks(xFile).VbProject.VBComponents.Import strTempFile...
 
I will change the topic name to " Export a .bas file from a workbook and export it to every workbooks of a folder." I came to the conclusion that if i need to open each workbook to import the . bas file, i need to unprotect them to proceed to the import part of the code...
 
I asked you: What kind of protection do you want removing? The one not letting the users viewing the VBA code?
 
10:51 AM
No, the macro one
to protect my macros
 
I am afraid we are talking two different languages. And I am not referring to English...
What do you mean by "protect my macros"?
Could you "protect your macros" in code?
What do you understand from the next question: The one not letting the users viewing the VBA code?
 
When you open Visual Basic, the VBAProject can be secured with a password
 
Then we are wasting our times... You cannot remove it in code in the way you try. It is much more complicated and I am afraid that your level of understanding VBA is a little to low for doing it.
No offence...
 
I know it will be hard haha, i'm just a beginner it's only 8 months i started
 
Microsoft did not create a method to directly do that.
 
10:57 AM
I'm not even sure i have to unprotect the workbook
If the rest of the code don't even work correctly i cannot be sure this is the part that block the macro
 
If it is protected, you cannot do what you want! You cannot even see the project, how to be allowed to change it?
 
Because i just add a module
 
Your code is wrong, anyhow. I tried explaining how to write a code line able to import a module. If you use the code as I recommended and have (in a test folder) only not protected xlsm workbooks, the code can easily adapted to work. Do it as i wrote in my above comment.
 
If i can modify a file without the macros activated that means i can add a .bas file without unprotect it maybe ?
 
I wish you a good day! We do not speak the same language, no offence...
You must learn VBA and its working principles before having such a discussion.
 
11:01 AM
Thanks anyway im doing it now
 
Bye!
 
Have a good day
 

last day (15 days later) »