VBA work on my computer and not on others with the same version

anzer

Board Regular
Joined
Mar 5, 2015
Messages
67
Hello,

I have a macro on my computer that works perfectly but it does not work on 2 others computers, but not the same lines...
I tested on a colleague (1) computer (Excel for office 365 MSO - 32 bits)
Some line at the very end of the macro has an error

With the macro I am creating a word document and skipping some line in word so this code line works on mine but not my colleage(1):
Error is on the last line showing :
Run-time error '91': Object variable or With block cariable not set

VBA Code:
Sub CreateWord()
Dim wordHeader As Variant
Set wordHeader = Sheets("...").Range("A7")
Dim wordName As Variant
Set wordName = Sheets("...").Range("A4")

Sheets("...").Activate
Dim PT As PivotTable
Set PT = ActiveSheet.PivotTables(1)
PT.TableRange1.Select
Selection.Copy
Dim myDoc As Word.Document
Dim wordapp
Dim strFile As String
strFile = "C:\Users\" & Environ$("username") & "\...\....docm"
Set wordapp = CreateObject("word.Application")
wordapp.Documents.Open strFile
wordapp.Visible = True
wordapp.Activate

Documents.Application.Selection.MoveDown Unit:=wdLine, Count:=2 (This line has an error on my colleague(1) computer but works on mine)


Then me second colleague(2) has a different error at the very beginning of the macro but this line works on my first colleague(1) computer and on mine
Error is on the Selection. line, error code is: Invalid Procedure call or argument '5'

VBA Code:
  Columns("A:F").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=IF($AA1>0,1,0)"


Why is it working on some computer then others don't and not always the same line
Since I created the macro for about 10 colleagues that will use them, if everyone has different errors it will be hell for me to fix them ahah

Thank you for your help in advance!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Why is it working on some computer then others don't and not always the same line
A common culprit is that they do not have the proper VB Libraries/References selected.

Go to a computer where it does work. Go into the VB Editor, and under the "Tools" menu, select "References". Note all the References that are selected.
Now go to a computer where it is not working, and do the same thing. Are they missing any of the selected References that the first computer has?
If so, look through the list and select the missing ones (note the version number might be slightly different). Then it should work on that computer.
 
Upvote 0
A common culprit is that they do not have the proper VB Libraries/References selected.

Go to a computer where it does work. Go into the VB Editor, and under the "Tools" menu, select "References". Note all the References that are selected.
Now go to a computer where it is not working, and do the same thing. Are they missing any of the selected References that the first computer has?
If so, look through the list and select the missing ones (note the version number might be slightly different). Then it should work on that computer.
Hello,

Just tried with my colleague (1) with the error 91 and it is not working even with all the same references :(

Thank you
 
Upvote 0
Hmmm... not sure then. There is either something different about their computer, environment, or files that they are running against.
Without having access to all of that, it can a bit different to figure out what might be happening.

I would recommend going to one of those computers, and stepping through the code line-by-line using the F8.
You want to set it so you can see both the VB Editor and the Worksheet/Word Document at the same time.
If you have two monitors, then show the VB Code on one, and the Documents on the other. Otherwise, re-size the VB Editor down to about 1/4 screen, so you can see both.
While you are stepping through the code, watch what is happening on the documents. Some times, the error becomes obvious when you see what is actually going on.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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