Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
654 views
in Technique[技术] by (71.8m points)

excel - Office 2016 -> 2013 "compile error, can't find project or library"

I just upgraded to Office 2016, which most of my users haven't done, and I'm getting a new error when users try to run my scripts.

"Compile Error, can't find project or library"

I looked in the references and it looks like it's trying to reference the "Microsoft Word 16.0 Object Library" and it's missing on machines running Office 2013. I don't see the option to change my reference to a 2013 version, and I don't know how to give my users access to the 2016 reference without upgrading everyone (not an option right now).

This error is coming up on the first executable line of code

Set app = Range("A2")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to include the Excel 15.0 Object Library in order to use Excel.Range("A2") like that or use late binding as shown below:

  Dim excelApp As object, r as object
  Set excelApp = CreateObject("Excel.Application")
  Set r = excelApp.Range("A2")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...