Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2022, 12:09 PM
VBAadvocate VBAadvocate is offline Application.Run with args fails Windows 10 Application.Run with args fails Office 2019
Novice
Application.Run with args fails
 
Join Date: Feb 2022
Posts: 12
VBAadvocate is on a distinguished road
Default Application.Run with args fails

After adding a template file to the Addins collection and installing the addin I can successfully run subs in the template that do not require any arguments.



However, if the sub requires an argument, it fails with the following error:
"Run-time error '438': Object doesn't support this property or method"

I am using the following line of code:

Application.Run strAddinFilename & "!SubName", strText

Where:
strAddinFileName - filename of the template with extension (not a full path)
SubName - name of a Sub
strText - name variable being passed as an argument to Sub.

I've modified the template sub using byVal and byRef for its arguments and various hacks using parens, the Call keyword and other junky ideas without any success.

According to the "About Word" on the Account page in Microsoft Word, I have:
Version 2112 (Build 14729.20322 Click-to-Run)

Hoping there's help, VBAadvocate
Reply With Quote
  #2  
Old 03-08-2022, 05:40 PM
Guessed's Avatar
Guessed Guessed is offline Application.Run with args fails Windows 10 Application.Run with args fails Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I did some searching and found this which looked promising for using the VBA Project name rather than the filename but I couldn't get that to work anyway.

I did get it going by adding a Reference pointing at the addin (shown via its VBA project name) and dropping the project name from the command that calls it.
Code:
Sub RunATest()
  'Include a reference to the addin's VBA project name (TestAddin)
  Application.Run "TestAddin!ShowMessage", "Specifying the Project Name fails"    'failed
  Application.Run "modName.ShowMessage", "Including the addin's module name works"    'worked
  Application.Run "ShowMessage", "Being even less specific works too"    'worked
End Sub
My addin contained a Public Function - you may need to make it Public as well. The code in the addin for my test was
Code:
Option Explicit

Public Function ShowMessage(sMsg As String)
  MsgBox sMsg
End Function

Sub aTest()
  ShowMessage "hello world"
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-09-2022, 05:50 AM
VBAadvocate VBAadvocate is offline Application.Run with args fails Windows 10 Application.Run with args fails Office 2019
Novice
Application.Run with args fails
 
Join Date: Feb 2022
Posts: 12
VBAadvocate is on a distinguished road
Default Application.Run with args fails, solved

Many thanks, Andrew.

I tried the following with success:
Application.Run "aMD_ForThisDocument.aMD_Document_ContentControlOn Enter", ctrl 'Works

I'm passing a reference to a ContentControl to a module routine in a stand-alone template which has nearly all the required code. However, I wanted to also have a seperate template that loads that stand-alone template and use its code. The stand-alone template's ThisDocument class calls the routines in its aMD_ForThisDocument module instead of having the code in the class mod and allow other projects use them. (Confusing? Probably. Sorry.)

Neverthelsess, I got it working. I tried including the addin's filename to help avoid having duplicate module names in various addins but that failed.

Thanks again, VBAadvocate (Jim)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Typing to cell fails DickVeitch Excel 6 11-20-2017 10:34 AM
SaveAs or Export to PDF fails Optiker Publisher 0 11-12-2017 12:17 PM
Application.Run with args fails MS Forms 2.0 library for 32 bit fails on x64 serge1p Excel Programming 1 09-21-2017 02:28 AM
Application.Run with args fails MS OneNote update repeated fails jlumbtx Office 1 01-07-2015 10:00 AM
Application.Run with args fails Office 2003 SP3 installation fails Mystified1 Office 4 02-07-2011 01:32 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:47 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft