How to integrate/link the .bas vba module file contents (variables) into the vba project?












1















We have 2 macros - say M1 and M2.



The M1 macro is working correctly.



The M2 macro is not working as expected (there are no compile/run-time errors) and the reason for this is that 1 file is missing in this macro M2. Say F1.bas. This file has the foll. code:



Public Const REG_SZ As Long = 1


The other files in the macro refer to this REG_SZ. On Macro M1 if I right click on the REG_SZ in the other files and click on Definition, then it takes me to the F1.bas file on this line.



However, on the M2 although I have imported the F1.bas file, and compiled the code; If I right click on the REG_SZ in the other files and click on Definition, then it gives an popup that says: "Identifier under cursor is not recognized".



My understanding is that any public variable in the module file should be globally accessible. Is there something that I am missing to establish the link, do we need to do something else when importing a module file?










share|improve this question




















  • 1





    Some minimal reproducible code would be good in order to understand your problem? Why do you need the .bas file? Did you maybe do a syntax error?

    – Lucas Raphael Pianegonda
    Nov 22 '18 at 7:30











  • No syntax error. Compiles OK. .bas file is needed because it has lot of more global variables. Its just basic code, it looks like the link is missing as explained in the question. I know that in some frameworks you need to include the other files, but in VBA my understanding is that anything declared as Public is global and available in any module file.

    – variable
    Nov 22 '18 at 7:38













  • try something like: F1.REG_SZ instead of just REG_SZ

    – Lucas Raphael Pianegonda
    Nov 22 '18 at 7:41











  • Yes, that works, but it will mean a lot of changes (find/replace) in the code which is not what I am looking; because the same concept works in the M1 macro by directly referring to REG_SZ, instead of F1.REG_SZ. ANy other suggestions please.

    – variable
    Nov 22 '18 at 8:16






  • 1





    Every .bas should start with OPTION EXPLICIT. That will avoid you some situations where a module compiles but gives a runtime error.

    – Patrick Honorez
    Nov 22 '18 at 9:53
















1















We have 2 macros - say M1 and M2.



The M1 macro is working correctly.



The M2 macro is not working as expected (there are no compile/run-time errors) and the reason for this is that 1 file is missing in this macro M2. Say F1.bas. This file has the foll. code:



Public Const REG_SZ As Long = 1


The other files in the macro refer to this REG_SZ. On Macro M1 if I right click on the REG_SZ in the other files and click on Definition, then it takes me to the F1.bas file on this line.



However, on the M2 although I have imported the F1.bas file, and compiled the code; If I right click on the REG_SZ in the other files and click on Definition, then it gives an popup that says: "Identifier under cursor is not recognized".



My understanding is that any public variable in the module file should be globally accessible. Is there something that I am missing to establish the link, do we need to do something else when importing a module file?










share|improve this question




















  • 1





    Some minimal reproducible code would be good in order to understand your problem? Why do you need the .bas file? Did you maybe do a syntax error?

    – Lucas Raphael Pianegonda
    Nov 22 '18 at 7:30











  • No syntax error. Compiles OK. .bas file is needed because it has lot of more global variables. Its just basic code, it looks like the link is missing as explained in the question. I know that in some frameworks you need to include the other files, but in VBA my understanding is that anything declared as Public is global and available in any module file.

    – variable
    Nov 22 '18 at 7:38













  • try something like: F1.REG_SZ instead of just REG_SZ

    – Lucas Raphael Pianegonda
    Nov 22 '18 at 7:41











  • Yes, that works, but it will mean a lot of changes (find/replace) in the code which is not what I am looking; because the same concept works in the M1 macro by directly referring to REG_SZ, instead of F1.REG_SZ. ANy other suggestions please.

    – variable
    Nov 22 '18 at 8:16






  • 1





    Every .bas should start with OPTION EXPLICIT. That will avoid you some situations where a module compiles but gives a runtime error.

    – Patrick Honorez
    Nov 22 '18 at 9:53














1












1








1








We have 2 macros - say M1 and M2.



The M1 macro is working correctly.



The M2 macro is not working as expected (there are no compile/run-time errors) and the reason for this is that 1 file is missing in this macro M2. Say F1.bas. This file has the foll. code:



Public Const REG_SZ As Long = 1


The other files in the macro refer to this REG_SZ. On Macro M1 if I right click on the REG_SZ in the other files and click on Definition, then it takes me to the F1.bas file on this line.



However, on the M2 although I have imported the F1.bas file, and compiled the code; If I right click on the REG_SZ in the other files and click on Definition, then it gives an popup that says: "Identifier under cursor is not recognized".



My understanding is that any public variable in the module file should be globally accessible. Is there something that I am missing to establish the link, do we need to do something else when importing a module file?










share|improve this question
















We have 2 macros - say M1 and M2.



The M1 macro is working correctly.



The M2 macro is not working as expected (there are no compile/run-time errors) and the reason for this is that 1 file is missing in this macro M2. Say F1.bas. This file has the foll. code:



Public Const REG_SZ As Long = 1


The other files in the macro refer to this REG_SZ. On Macro M1 if I right click on the REG_SZ in the other files and click on Definition, then it takes me to the F1.bas file on this line.



However, on the M2 although I have imported the F1.bas file, and compiled the code; If I right click on the REG_SZ in the other files and click on Definition, then it gives an popup that says: "Identifier under cursor is not recognized".



My understanding is that any public variable in the module file should be globally accessible. Is there something that I am missing to establish the link, do we need to do something else when importing a module file?







vba ms-word






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 10:51







variable

















asked Nov 22 '18 at 7:03









variablevariable

96321840




96321840








  • 1





    Some minimal reproducible code would be good in order to understand your problem? Why do you need the .bas file? Did you maybe do a syntax error?

    – Lucas Raphael Pianegonda
    Nov 22 '18 at 7:30











  • No syntax error. Compiles OK. .bas file is needed because it has lot of more global variables. Its just basic code, it looks like the link is missing as explained in the question. I know that in some frameworks you need to include the other files, but in VBA my understanding is that anything declared as Public is global and available in any module file.

    – variable
    Nov 22 '18 at 7:38













  • try something like: F1.REG_SZ instead of just REG_SZ

    – Lucas Raphael Pianegonda
    Nov 22 '18 at 7:41











  • Yes, that works, but it will mean a lot of changes (find/replace) in the code which is not what I am looking; because the same concept works in the M1 macro by directly referring to REG_SZ, instead of F1.REG_SZ. ANy other suggestions please.

    – variable
    Nov 22 '18 at 8:16






  • 1





    Every .bas should start with OPTION EXPLICIT. That will avoid you some situations where a module compiles but gives a runtime error.

    – Patrick Honorez
    Nov 22 '18 at 9:53














  • 1





    Some minimal reproducible code would be good in order to understand your problem? Why do you need the .bas file? Did you maybe do a syntax error?

    – Lucas Raphael Pianegonda
    Nov 22 '18 at 7:30











  • No syntax error. Compiles OK. .bas file is needed because it has lot of more global variables. Its just basic code, it looks like the link is missing as explained in the question. I know that in some frameworks you need to include the other files, but in VBA my understanding is that anything declared as Public is global and available in any module file.

    – variable
    Nov 22 '18 at 7:38













  • try something like: F1.REG_SZ instead of just REG_SZ

    – Lucas Raphael Pianegonda
    Nov 22 '18 at 7:41











  • Yes, that works, but it will mean a lot of changes (find/replace) in the code which is not what I am looking; because the same concept works in the M1 macro by directly referring to REG_SZ, instead of F1.REG_SZ. ANy other suggestions please.

    – variable
    Nov 22 '18 at 8:16






  • 1





    Every .bas should start with OPTION EXPLICIT. That will avoid you some situations where a module compiles but gives a runtime error.

    – Patrick Honorez
    Nov 22 '18 at 9:53








1




1





Some minimal reproducible code would be good in order to understand your problem? Why do you need the .bas file? Did you maybe do a syntax error?

– Lucas Raphael Pianegonda
Nov 22 '18 at 7:30





Some minimal reproducible code would be good in order to understand your problem? Why do you need the .bas file? Did you maybe do a syntax error?

– Lucas Raphael Pianegonda
Nov 22 '18 at 7:30













No syntax error. Compiles OK. .bas file is needed because it has lot of more global variables. Its just basic code, it looks like the link is missing as explained in the question. I know that in some frameworks you need to include the other files, but in VBA my understanding is that anything declared as Public is global and available in any module file.

– variable
Nov 22 '18 at 7:38







No syntax error. Compiles OK. .bas file is needed because it has lot of more global variables. Its just basic code, it looks like the link is missing as explained in the question. I know that in some frameworks you need to include the other files, but in VBA my understanding is that anything declared as Public is global and available in any module file.

– variable
Nov 22 '18 at 7:38















try something like: F1.REG_SZ instead of just REG_SZ

– Lucas Raphael Pianegonda
Nov 22 '18 at 7:41





try something like: F1.REG_SZ instead of just REG_SZ

– Lucas Raphael Pianegonda
Nov 22 '18 at 7:41













Yes, that works, but it will mean a lot of changes (find/replace) in the code which is not what I am looking; because the same concept works in the M1 macro by directly referring to REG_SZ, instead of F1.REG_SZ. ANy other suggestions please.

– variable
Nov 22 '18 at 8:16





Yes, that works, but it will mean a lot of changes (find/replace) in the code which is not what I am looking; because the same concept works in the M1 macro by directly referring to REG_SZ, instead of F1.REG_SZ. ANy other suggestions please.

– variable
Nov 22 '18 at 8:16




1




1





Every .bas should start with OPTION EXPLICIT. That will avoid you some situations where a module compiles but gives a runtime error.

– Patrick Honorez
Nov 22 '18 at 9:53





Every .bas should start with OPTION EXPLICIT. That will avoid you some situations where a module compiles but gives a runtime error.

– Patrick Honorez
Nov 22 '18 at 9:53












1 Answer
1






active

oldest

votes


















1














May i suggest that instead of importing F1.bas, create a new module next to M1/M2 and copy contents of F1.



I was able to reproduce your problem, and copying the contents instead of just importing seems to be processed differently by the editor. As for the reasons why... I can't help.



Further testing shows that commenting your variable Public Const REG_SZ As Long = 1 and uncommenting it, forces the editor to recognise it again (from the imported file).



Hope this helps.






share|improve this answer





















  • 1





    Thanks man, that works!

    – variable
    Nov 22 '18 at 10:15













  • Do you know if there is any way to identify such broken links (in my case there was no compile/run-time error)?

    – variable
    Nov 22 '18 at 10:44













  • Could make a sub to debug.print each variable... can't think of a better way. Sub test() If REG_SZ <> 1 Then Debug.Print "REG_SZ link missing." End Sub

    – DarXyde
    Nov 22 '18 at 12:35











  • Answer: stackoverflow.com/questions/53429300/…

    – variable
    Nov 23 '18 at 5:51











  • I always use Option Explicit at the top for my code, though not for quick testing like for your case... so yeah, that's another way, but it will pretty much stop you at one variable at the time... not particularly useful in your case, depending how often you need to import your modules.

    – DarXyde
    Nov 23 '18 at 10:12











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425480%2fhow-to-integrate-link-the-bas-vba-module-file-contents-variables-into-the-vba%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














May i suggest that instead of importing F1.bas, create a new module next to M1/M2 and copy contents of F1.



I was able to reproduce your problem, and copying the contents instead of just importing seems to be processed differently by the editor. As for the reasons why... I can't help.



Further testing shows that commenting your variable Public Const REG_SZ As Long = 1 and uncommenting it, forces the editor to recognise it again (from the imported file).



Hope this helps.






share|improve this answer





















  • 1





    Thanks man, that works!

    – variable
    Nov 22 '18 at 10:15













  • Do you know if there is any way to identify such broken links (in my case there was no compile/run-time error)?

    – variable
    Nov 22 '18 at 10:44













  • Could make a sub to debug.print each variable... can't think of a better way. Sub test() If REG_SZ <> 1 Then Debug.Print "REG_SZ link missing." End Sub

    – DarXyde
    Nov 22 '18 at 12:35











  • Answer: stackoverflow.com/questions/53429300/…

    – variable
    Nov 23 '18 at 5:51











  • I always use Option Explicit at the top for my code, though not for quick testing like for your case... so yeah, that's another way, but it will pretty much stop you at one variable at the time... not particularly useful in your case, depending how often you need to import your modules.

    – DarXyde
    Nov 23 '18 at 10:12
















1














May i suggest that instead of importing F1.bas, create a new module next to M1/M2 and copy contents of F1.



I was able to reproduce your problem, and copying the contents instead of just importing seems to be processed differently by the editor. As for the reasons why... I can't help.



Further testing shows that commenting your variable Public Const REG_SZ As Long = 1 and uncommenting it, forces the editor to recognise it again (from the imported file).



Hope this helps.






share|improve this answer





















  • 1





    Thanks man, that works!

    – variable
    Nov 22 '18 at 10:15













  • Do you know if there is any way to identify such broken links (in my case there was no compile/run-time error)?

    – variable
    Nov 22 '18 at 10:44













  • Could make a sub to debug.print each variable... can't think of a better way. Sub test() If REG_SZ <> 1 Then Debug.Print "REG_SZ link missing." End Sub

    – DarXyde
    Nov 22 '18 at 12:35











  • Answer: stackoverflow.com/questions/53429300/…

    – variable
    Nov 23 '18 at 5:51











  • I always use Option Explicit at the top for my code, though not for quick testing like for your case... so yeah, that's another way, but it will pretty much stop you at one variable at the time... not particularly useful in your case, depending how often you need to import your modules.

    – DarXyde
    Nov 23 '18 at 10:12














1












1








1







May i suggest that instead of importing F1.bas, create a new module next to M1/M2 and copy contents of F1.



I was able to reproduce your problem, and copying the contents instead of just importing seems to be processed differently by the editor. As for the reasons why... I can't help.



Further testing shows that commenting your variable Public Const REG_SZ As Long = 1 and uncommenting it, forces the editor to recognise it again (from the imported file).



Hope this helps.






share|improve this answer















May i suggest that instead of importing F1.bas, create a new module next to M1/M2 and copy contents of F1.



I was able to reproduce your problem, and copying the contents instead of just importing seems to be processed differently by the editor. As for the reasons why... I can't help.



Further testing shows that commenting your variable Public Const REG_SZ As Long = 1 and uncommenting it, forces the editor to recognise it again (from the imported file).



Hope this helps.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 9:44

























answered Nov 22 '18 at 9:37









DarXydeDarXyde

24016




24016








  • 1





    Thanks man, that works!

    – variable
    Nov 22 '18 at 10:15













  • Do you know if there is any way to identify such broken links (in my case there was no compile/run-time error)?

    – variable
    Nov 22 '18 at 10:44













  • Could make a sub to debug.print each variable... can't think of a better way. Sub test() If REG_SZ <> 1 Then Debug.Print "REG_SZ link missing." End Sub

    – DarXyde
    Nov 22 '18 at 12:35











  • Answer: stackoverflow.com/questions/53429300/…

    – variable
    Nov 23 '18 at 5:51











  • I always use Option Explicit at the top for my code, though not for quick testing like for your case... so yeah, that's another way, but it will pretty much stop you at one variable at the time... not particularly useful in your case, depending how often you need to import your modules.

    – DarXyde
    Nov 23 '18 at 10:12














  • 1





    Thanks man, that works!

    – variable
    Nov 22 '18 at 10:15













  • Do you know if there is any way to identify such broken links (in my case there was no compile/run-time error)?

    – variable
    Nov 22 '18 at 10:44













  • Could make a sub to debug.print each variable... can't think of a better way. Sub test() If REG_SZ <> 1 Then Debug.Print "REG_SZ link missing." End Sub

    – DarXyde
    Nov 22 '18 at 12:35











  • Answer: stackoverflow.com/questions/53429300/…

    – variable
    Nov 23 '18 at 5:51











  • I always use Option Explicit at the top for my code, though not for quick testing like for your case... so yeah, that's another way, but it will pretty much stop you at one variable at the time... not particularly useful in your case, depending how often you need to import your modules.

    – DarXyde
    Nov 23 '18 at 10:12








1




1





Thanks man, that works!

– variable
Nov 22 '18 at 10:15







Thanks man, that works!

– variable
Nov 22 '18 at 10:15















Do you know if there is any way to identify such broken links (in my case there was no compile/run-time error)?

– variable
Nov 22 '18 at 10:44







Do you know if there is any way to identify such broken links (in my case there was no compile/run-time error)?

– variable
Nov 22 '18 at 10:44















Could make a sub to debug.print each variable... can't think of a better way. Sub test() If REG_SZ <> 1 Then Debug.Print "REG_SZ link missing." End Sub

– DarXyde
Nov 22 '18 at 12:35





Could make a sub to debug.print each variable... can't think of a better way. Sub test() If REG_SZ <> 1 Then Debug.Print "REG_SZ link missing." End Sub

– DarXyde
Nov 22 '18 at 12:35













Answer: stackoverflow.com/questions/53429300/…

– variable
Nov 23 '18 at 5:51





Answer: stackoverflow.com/questions/53429300/…

– variable
Nov 23 '18 at 5:51













I always use Option Explicit at the top for my code, though not for quick testing like for your case... so yeah, that's another way, but it will pretty much stop you at one variable at the time... not particularly useful in your case, depending how often you need to import your modules.

– DarXyde
Nov 23 '18 at 10:12





I always use Option Explicit at the top for my code, though not for quick testing like for your case... so yeah, that's another way, but it will pretty much stop you at one variable at the time... not particularly useful in your case, depending how often you need to import your modules.

– DarXyde
Nov 23 '18 at 10:12


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425480%2fhow-to-integrate-link-the-bas-vba-module-file-contents-variables-into-the-vba%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen