Macro not running on other computers

DK340

New Member
Joined
Oct 13, 2009
Messages
17
I have a macro that I created on my desktop and it works perfectly well. I sent the file to another co-worker and it fails. The macro basically opens another excel sheet, copies a few things, pastes them in the spreadsheet where the macro resides and then closes the other opened document.

The code that closes the opened document that I am using is:

Windows(Filename).Close SaveChanges:=False

The macro fails on everyone elses computer but mine when it tries to close the opened document that it is copying from. If I eliminate the above code so that the document stays open, the macro works fine. Is there something that can correct this so that it can work on other computers? Thanks.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Rather than depend upon the caption, set a reference to the other wb.

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br>    <br><SPAN style="color:#00007F">Sub</SPAN> exa()<br><SPAN style="color:#00007F">Dim</SPAN> wbOther <SPAN style="color:#00007F">As</SPAN> Workbook<br><SPAN style="color:#00007F">Dim</SPAN> wksSource <SPAN style="color:#00007F">As</SPAN> Worksheet<br><SPAN style="color:#00007F">Dim</SPAN> rngSource <SPAN style="color:#00007F">As</SPAN> Range<br><SPAN style="color:#00007F">Dim</SPAN> strPath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> strWBName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <br>    strPath = ThisWorkbook.Path & "\"<br>    strWBName = "Test.xls"<br>    <br>    <SPAN style="color:#007F00">'// Set a reference to the other workbook upon opening.  This allows better conrol  //</SPAN><br>    <SPAN style="color:#007F00">'// over it.                                                                        //</SPAN><br>    <SPAN style="color:#00007F">Set</SPAN> wbOther = Workbooks.Open(strPath & strWBName)<br>    <SPAN style="color:#00007F">Set</SPAN> wksSource = wbOther.Worksheets("Sheet1")<br>    <SPAN style="color:#00007F">Set</SPAN> rngSource = wksSource.Range("A1:A3")<br>    <br>    rngSource.Copy ThisWorkbook.Worksheets("Sheet2").Range("A1")<br>    <br>    wbOther.Close <SPAN style="color:#00007F">False</SPAN><br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top