Reference in Excel VBA code does not work the first time program is startedHow to pause for specific amount of time? (Excel/VBA)MSXML2.DOMDocument60 crashes ExcelExcel Addins and Extra Driversexcel replace function in access vbaExecute AutoIt and wait for finishExcel VBA reference for Inet objectsVBA Calling C++ DLL - error 48 (file not found)OneNote2013-Reference to undeclared namespace prefix:'one' errormsxml2.xmlhttp IE 11 vs ChromeExcel stops responding while executing loop

How to plan the font size in a fiction?

Single level file directory

How do I tell the reader that my character is autistic in Fantasy?

Who voices the character "Finger" in The Fifth Element?

Different budgets within roommate group

Was it really unprofessional of me to leave without asking for a raise first?

How to properly say asset/assets in German

Why was Mal so quick to drop Bester in favour of Kaylee?

Warnings of R. Chaim Vital

What do you call a notepad used to keep a record?

Why did NASA wet the road in front of the Space Shuttle crawler?

Losing queen and then winning the game

How to define a macro inside a macro via if?

What kind of jet plane is this?

Golf the smallest circle!

Can European countries bypass the EU and make their own individual trade deal with the U.S.?

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

What does grep -v "grep" mean and do?

Is there any way to adjust the component values to get 5V output?

sorting 4 numbers using Min - Max boxes

How do I ensure my employees don't abuse my flexible work hours policy?

Is is okay to submit a paper from a master's thesis without informing the advisor?

How did Lefschetz do mathematics without hands?

How receiver knows the exact frequency in the channel to "listen to"?



Reference in Excel VBA code does not work the first time program is started


How to pause for specific amount of time? (Excel/VBA)MSXML2.DOMDocument60 crashes ExcelExcel Addins and Extra Driversexcel replace function in access vbaExecute AutoIt and wait for finishExcel VBA reference for Inet objectsVBA Calling C++ DLL - error 48 (file not found)OneNote2013-Reference to undeclared namespace prefix:'one' errormsxml2.xmlhttp IE 11 vs ChromeExcel stops responding while executing loop






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I do some coding of Excel AddIns (using Excel 2016), which have to be used by another user (using Excel 365), too.



In order to manipulate XML, I added the reference to Microsoft XML, v6.0; everything works perfectly fine on my machine.



Running the code on the other user's machine shows that the reference is not checked (although the underyling dll is available at the expected file location).



I added some code to programmatically add the reference (no error handling yet):



Sub AddXmlReference() 
Dim ref As Reference
Dim existRef As Boolean
existRef = False

For Each ref In Application.VBE.ActiveVBProject.References
If ref.Name = "MSXML2" Then
existRef = True
End If
Next ref

If existRef = False Then
Application.VBE.ActiveVBProject.References.AddFromFile "C:WindowsSysWOW64msxml6.dll"
End If
End Sub


Starting the program on the other user's machine shows some behaviour I do not understand (and I could not find anything helpful):
The first time the program is executed, it runs into an error (user defined error at the module that tries to manipulate XML); thereafter, the program works nicely. If I close excel and restart, the same behaviour starts again. Summarizing, it looks like:



  • Excel does not store the reference (which in a way is understandable, as the underlying code dercertain reasons is is opened read-only; in a way however it is not, as the underlying code does have the reference)


  • Whilst running the code, the added reference cannot be used


  • Within one excel session, the reference is stored


Is there a way to make this added reference being stored permanently? Or did I miss something out?










share|improve this question



















  • 2





    Until recently the default installation of Office 365 was 32 bit. What version does your user have, 32 or 64 bit.

    – Freeflow
    Mar 25 at 14:16






  • 1





    Have you trusted access to the VBA Project Object Model from Macro Settings?

    – Foxfire And Burns And Burns
    Mar 25 at 14:18






  • 2





    Actually the references are added to a specific file not to Excel, so if you save that file after the reference was added the reference should be stored permanently. So if your file is an add-in you need to save that add-in. • Alternatively use LateBinding instead of EarlyBinding to avoid that references need to be added at all.

    – Pᴇʜ
    Mar 25 at 14:19







  • 1





    PEH says it and I think it's important to know what Early and Late Binding mean and to understand the differences..

    – user2261597
    Mar 25 at 14:24






  • 2





    References are workbook-specific as has been said. It is not possible for the same workbook to have different references set.

    – Rory
    Mar 25 at 15:18

















1















I do some coding of Excel AddIns (using Excel 2016), which have to be used by another user (using Excel 365), too.



In order to manipulate XML, I added the reference to Microsoft XML, v6.0; everything works perfectly fine on my machine.



Running the code on the other user's machine shows that the reference is not checked (although the underyling dll is available at the expected file location).



I added some code to programmatically add the reference (no error handling yet):



Sub AddXmlReference() 
Dim ref As Reference
Dim existRef As Boolean
existRef = False

For Each ref In Application.VBE.ActiveVBProject.References
If ref.Name = "MSXML2" Then
existRef = True
End If
Next ref

If existRef = False Then
Application.VBE.ActiveVBProject.References.AddFromFile "C:WindowsSysWOW64msxml6.dll"
End If
End Sub


Starting the program on the other user's machine shows some behaviour I do not understand (and I could not find anything helpful):
The first time the program is executed, it runs into an error (user defined error at the module that tries to manipulate XML); thereafter, the program works nicely. If I close excel and restart, the same behaviour starts again. Summarizing, it looks like:



  • Excel does not store the reference (which in a way is understandable, as the underlying code dercertain reasons is is opened read-only; in a way however it is not, as the underlying code does have the reference)


  • Whilst running the code, the added reference cannot be used


  • Within one excel session, the reference is stored


Is there a way to make this added reference being stored permanently? Or did I miss something out?










share|improve this question



















  • 2





    Until recently the default installation of Office 365 was 32 bit. What version does your user have, 32 or 64 bit.

    – Freeflow
    Mar 25 at 14:16






  • 1





    Have you trusted access to the VBA Project Object Model from Macro Settings?

    – Foxfire And Burns And Burns
    Mar 25 at 14:18






  • 2





    Actually the references are added to a specific file not to Excel, so if you save that file after the reference was added the reference should be stored permanently. So if your file is an add-in you need to save that add-in. • Alternatively use LateBinding instead of EarlyBinding to avoid that references need to be added at all.

    – Pᴇʜ
    Mar 25 at 14:19







  • 1





    PEH says it and I think it's important to know what Early and Late Binding mean and to understand the differences..

    – user2261597
    Mar 25 at 14:24






  • 2





    References are workbook-specific as has been said. It is not possible for the same workbook to have different references set.

    – Rory
    Mar 25 at 15:18













1












1








1








I do some coding of Excel AddIns (using Excel 2016), which have to be used by another user (using Excel 365), too.



In order to manipulate XML, I added the reference to Microsoft XML, v6.0; everything works perfectly fine on my machine.



Running the code on the other user's machine shows that the reference is not checked (although the underyling dll is available at the expected file location).



I added some code to programmatically add the reference (no error handling yet):



Sub AddXmlReference() 
Dim ref As Reference
Dim existRef As Boolean
existRef = False

For Each ref In Application.VBE.ActiveVBProject.References
If ref.Name = "MSXML2" Then
existRef = True
End If
Next ref

If existRef = False Then
Application.VBE.ActiveVBProject.References.AddFromFile "C:WindowsSysWOW64msxml6.dll"
End If
End Sub


Starting the program on the other user's machine shows some behaviour I do not understand (and I could not find anything helpful):
The first time the program is executed, it runs into an error (user defined error at the module that tries to manipulate XML); thereafter, the program works nicely. If I close excel and restart, the same behaviour starts again. Summarizing, it looks like:



  • Excel does not store the reference (which in a way is understandable, as the underlying code dercertain reasons is is opened read-only; in a way however it is not, as the underlying code does have the reference)


  • Whilst running the code, the added reference cannot be used


  • Within one excel session, the reference is stored


Is there a way to make this added reference being stored permanently? Or did I miss something out?










share|improve this question
















I do some coding of Excel AddIns (using Excel 2016), which have to be used by another user (using Excel 365), too.



In order to manipulate XML, I added the reference to Microsoft XML, v6.0; everything works perfectly fine on my machine.



Running the code on the other user's machine shows that the reference is not checked (although the underyling dll is available at the expected file location).



I added some code to programmatically add the reference (no error handling yet):



Sub AddXmlReference() 
Dim ref As Reference
Dim existRef As Boolean
existRef = False

For Each ref In Application.VBE.ActiveVBProject.References
If ref.Name = "MSXML2" Then
existRef = True
End If
Next ref

If existRef = False Then
Application.VBE.ActiveVBProject.References.AddFromFile "C:WindowsSysWOW64msxml6.dll"
End If
End Sub


Starting the program on the other user's machine shows some behaviour I do not understand (and I could not find anything helpful):
The first time the program is executed, it runs into an error (user defined error at the module that tries to manipulate XML); thereafter, the program works nicely. If I close excel and restart, the same behaviour starts again. Summarizing, it looks like:



  • Excel does not store the reference (which in a way is understandable, as the underlying code dercertain reasons is is opened read-only; in a way however it is not, as the underlying code does have the reference)


  • Whilst running the code, the added reference cannot be used


  • Within one excel session, the reference is stored


Is there a way to make this added reference being stored permanently? Or did I miss something out?







excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 14:17









Pᴇʜ

28.1k6 gold badges30 silver badges54 bronze badges




28.1k6 gold badges30 silver badges54 bronze badges










asked Mar 25 at 14:09









alexanderalexander

208 bronze badges




208 bronze badges







  • 2





    Until recently the default installation of Office 365 was 32 bit. What version does your user have, 32 or 64 bit.

    – Freeflow
    Mar 25 at 14:16






  • 1





    Have you trusted access to the VBA Project Object Model from Macro Settings?

    – Foxfire And Burns And Burns
    Mar 25 at 14:18






  • 2





    Actually the references are added to a specific file not to Excel, so if you save that file after the reference was added the reference should be stored permanently. So if your file is an add-in you need to save that add-in. • Alternatively use LateBinding instead of EarlyBinding to avoid that references need to be added at all.

    – Pᴇʜ
    Mar 25 at 14:19







  • 1





    PEH says it and I think it's important to know what Early and Late Binding mean and to understand the differences..

    – user2261597
    Mar 25 at 14:24






  • 2





    References are workbook-specific as has been said. It is not possible for the same workbook to have different references set.

    – Rory
    Mar 25 at 15:18












  • 2





    Until recently the default installation of Office 365 was 32 bit. What version does your user have, 32 or 64 bit.

    – Freeflow
    Mar 25 at 14:16






  • 1





    Have you trusted access to the VBA Project Object Model from Macro Settings?

    – Foxfire And Burns And Burns
    Mar 25 at 14:18






  • 2





    Actually the references are added to a specific file not to Excel, so if you save that file after the reference was added the reference should be stored permanently. So if your file is an add-in you need to save that add-in. • Alternatively use LateBinding instead of EarlyBinding to avoid that references need to be added at all.

    – Pᴇʜ
    Mar 25 at 14:19







  • 1





    PEH says it and I think it's important to know what Early and Late Binding mean and to understand the differences..

    – user2261597
    Mar 25 at 14:24






  • 2





    References are workbook-specific as has been said. It is not possible for the same workbook to have different references set.

    – Rory
    Mar 25 at 15:18







2




2





Until recently the default installation of Office 365 was 32 bit. What version does your user have, 32 or 64 bit.

– Freeflow
Mar 25 at 14:16





Until recently the default installation of Office 365 was 32 bit. What version does your user have, 32 or 64 bit.

– Freeflow
Mar 25 at 14:16




1




1





Have you trusted access to the VBA Project Object Model from Macro Settings?

– Foxfire And Burns And Burns
Mar 25 at 14:18





Have you trusted access to the VBA Project Object Model from Macro Settings?

– Foxfire And Burns And Burns
Mar 25 at 14:18




2




2





Actually the references are added to a specific file not to Excel, so if you save that file after the reference was added the reference should be stored permanently. So if your file is an add-in you need to save that add-in. • Alternatively use LateBinding instead of EarlyBinding to avoid that references need to be added at all.

– Pᴇʜ
Mar 25 at 14:19






Actually the references are added to a specific file not to Excel, so if you save that file after the reference was added the reference should be stored permanently. So if your file is an add-in you need to save that add-in. • Alternatively use LateBinding instead of EarlyBinding to avoid that references need to be added at all.

– Pᴇʜ
Mar 25 at 14:19





1




1





PEH says it and I think it's important to know what Early and Late Binding mean and to understand the differences..

– user2261597
Mar 25 at 14:24





PEH says it and I think it's important to know what Early and Late Binding mean and to understand the differences..

– user2261597
Mar 25 at 14:24




2




2





References are workbook-specific as has been said. It is not possible for the same workbook to have different references set.

– Rory
Mar 25 at 15:18





References are workbook-specific as has been said. It is not possible for the same workbook to have different references set.

– Rory
Mar 25 at 15:18












0






active

oldest

votes










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%2f55339729%2freference-in-excel-vba-code-does-not-work-the-first-time-program-is-started%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















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%2f55339729%2freference-in-excel-vba-code-does-not-work-the-first-time-program-is-started%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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해