Sub or Function not defined (Why ??)

I have a template that contains a userform module named "MACROS" and a =
=3D
standard code module named "Code." I have exported both of these =3D
modules to my C:\ directory.

I have another large collection of tempaltes that each contain code in =
=3D
the "ThisDocument" clase module and a standard code module named =3D
"NewMacros"

I have written a procedure to process some changes to each of these =3D
templates. The procedure opens each document and passes the document =3D
object to the procedure shown below which peforms the following =3D
functions:

1. Removes all code lines from the ThisDocument class module
2. Deletes the NewMacros code module
3. Imports the Userform "MACROS" and standard code module "Code."

Sub ImportFormAndCodeModules(ByRef Doc As Word.Document)
Dim vbProj As VBProject
Dim vbComp As VBComponent
Set vbProj =3D3D ActiveDocument.VBProject
Set vbComp =3D3D vbProj.VBComponents("ThisDocument")
'Clear any lines in "ThisDocument"
Do While vbComp.CodeModule.CountOfLines > 0
vbComp.CodeModule.DeleteLines 1
Loop
'Delete "NewMacros" code module
Set vbComp =3D3D vbProj.VBComponents("NewMacros")
Application.OrganizerDelete Source:=3D3DDoc.FullName, =
Name:=3D3DvbComp.Name, =3D
Object:=3D3DwdOrganizerObjectProjectItems
'Import new userform and code modules.
'For testing
vbProj.VBComponents.Import "C:\MACROS.frm"
vbProj.VBComponents.Import "C:\Code.bas"
End Sub

The processing appears to work as expected. There is one problem =3D
though. The "Code" module contains an AutoOpen procedure shown below:

Sub AutoOpen()
Options.ButtonFieldClicks =3D3D 1
MACROS.Show
With MACROS
..Top =3D3D Application.Top
..Left =3D3D Application.Left
End With
End Sub

After the process has been run, when I attempt to open some of the =3D
documents (some but not all) then I get an error message "Sub or =3D
Function Not Defined." When I "OK" out of the error message the =3D
document opens but hte AutoOpen procedure clearly did not run.

Now if open the VBE and make the slightest change to the AutoOpen =3D
procedure (e.g., delete one character and add it right back) then save =
=3D
the template it will open normally from then on.

Can anyone explain this behaviour and what, if anything, I can do to =3D
ensure the Code module is imported cleanly and fully so that this error =
=3D
will not occur?

Thanks.


--=20
Greg Maxey

Please visit my web site http://gregmaxey.mvps.org

Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)
 =20

0
Greg
6/3/2010 11:01:09 PM
word.vba.general 1023 articles. 1 followers. Follow

0 Replies
3548 Views

Similar Articles

[PageSpeed] 54

Reply:

Similar Artilces:

can some one explain to me the count(if()) function??
i got this array formula... where e4:e86, aq6 and aq5 are dates ={COUNT(IF(($E$4:$E$86>=AQ6)*($E$4:$E$86<=AQ5),$E$4:$E$86))} i understand it... but how does it differ to say a "countif" function? can the above function be simplified -- Message posted from http://www.ExcelForum.com The COUNTIF function can handle only one condition while yours has two. =COUNTIF(E4:E86,">="&AQ6) -- Jim Rech Excel MVP "sokevin >" <<sokevin.17x8wh@excelforum-nospam.com> wrote in message news:sokevin.17x8wh@excelforum-nospam.com... |i got this ar...

IF Function not working
The first and second IF functions are working, but not the third: =IF(B1<B2,C1*.005,IF(B1>=B2,C1*.01,IF(B1>=B3,C1*.012))) I assume it has something to do with the >= but I don't know another way. Thank you. There is no indication on what action should be taken if B1<B3, the False condition http://HelpExcel.com "sonicj" wrote: > The first and second IF functions are working, but not the third: > =IF(B1<B2,C1*.005,IF(B1>=B2,C1*.01,IF(B1>=B3,C1*.012))) > I assume it has something to do with the >= but I don't know another way. > T...

What's the floating point function for triple (or quadruple) roots?
Hi, Can someone tell me the floating point function for triple (or quadruple) roots, someting like sqrt() for square roots? Thanks. Tony Follow the rules of indecease. Square root = x^(1/<power>) So Cube root = x^(1/3) -- - Mark Randall http://zetech.swehli.com "Tony Young" <jdt_young@yahoo.com> wrote in message news:OunMTa4SFHA.3636@TK2MSFTNGP14.phx.gbl... > Hi, > > Can someone tell me the floating point function for triple (or quadruple) > roots, someting like sqrt() for square roots? Thanks. > > Tony /------------- p \ / ...

Referencing more than 2 sheets in one cell function?
I am trying to take information from four different sheets in my workbook to create one function in my fifth sheet. So far, the function works with information from one sheet and two sheets but I cannot add the reference to the third sheet to the funtion without errors. Perhaps if you showed us the code for the non-working function and described in more detail what you have now on the four sheets and what you want the function to output when it is done, then someone here may be able to offer you some comments as to how you should proceed. -- Rick (MVP - Excel) "A...

Web Excel and Excel Functions
I’m working with a worksheet using Web Excel or CPM (Everest). As such I’m combining functions from excel and web excel. Web Excel recognizes dates in the following formats: 2009.Nov, FY2010Total (This represents my fiscal year which ends on 6/30 each year), 2009.Nov.30, CY2010Total (normal calendar year), and of course the date formats in Excel. Because I’m working with the different formats, it’s necessary to use the concatenate function and if statements, to give the date formats I need. I have the following formula in a cell to give me the date in the format 2009.N...

How to clear "linest ( ) function error " in regression analysis?
I am not able to clear the error( "linest ( ) function error") while working on regression analysis of the tool pack. How do I get rid of this error? ...

NZ Function -- PLEASE HELP!!
Hi All, I have a query, and in this query I am calculating Difference. So thats what I have: Difference: ([Quantum Daily Trading]-nz([C1 PnL Attribution Actual], 0)) Everything is working good, but C1 PnL Attribution Actual has a NULL value. So query spits an empty field, and my manager wants to see 0. Please resond to: bori.teitelbaev@morganstanley.com Thanks in advance, B If C1 PnL Attribution Actual is Null, then the Nz function will replace it with 0. Are you sure it's not Quantum Daily Trading that's Null? -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele ...

RATE function source code
Hi, I need to mimic what the RATE function in Excel does behind the scenes. I know what to enter into the RATE function. Basically, I am writing a program in another programming language that needs to find an interest rate when given the inputs that are used for the RATE function. Does anyone have any idea if it is possible to see the real equation for the RATE function or if you know what it is can you post it please? Thanks. ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.c...

possible to return to values from function?
Thanks in advance. I want to make a function that can return two values, is that possible? Or is one the absolute limit? Thanks again. ="this is function one"&(1*2)&"this is function 2"&(2*3) "Ian Elliott" <iane@hotmail.com> wrote in message news:0c2701c36c15$aa260fc0$a001280a@phx.gbl... > Thanks in advance. > > I want to make a function that can return two values, is > that possible? Or is one the absolute limit? > Thanks again. > ...

Select all calendar function?
I frequently have to copy/move several meetings from one day to another. Is there any way to "select all" meetings from one day, then copy and move them to another? Currently, I single click on each individual meeting while holding down the ctrl key, but this is rather time consuming. you can hold ctrl as you click to select appt to select multiple ones. hold shift when you select the first appt to be moved and then select the last one and you'll select all in between. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Need Help with Common T...

User Defined config section "You must implement a default accessor on System.Configuration.ConfigurationLockCollection because it inherits from ICollection."
""You must implement a default accessor on System.Configuration.ConfigurationLockCollection because it inherits from ICollection."" Hello All, I am having my app.config file like : <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="PredefinedClusters" type="BinaryChecker.ClusterSection,BinaryChecker"/> </configSections> <PredefinedClusters> <Cluster name="Portal"> <Environments> <Env name="a...

Using RANK Function
I need to rank 225 rows of data. Can I use the replace function so D4:D229 appears in each cell? Thanks for the help. Skip Skip, Use $D$4:$D$229 as the range reference in your RANK function, and it won't change when you copy the formula. HTH, Bernie MS Excel MVP "Skip" <ssummer@earthlink.net> wrote in message news:4a482838-1cf3-419c-8e7a-2d4a17bb9f3e@s50g2000hsb.googlegroups.com... >I need to rank 225 rows of data. Can I use the replace function so > D4:D229 appears in each cell? Thanks for the help. > Skip ...

IF FUNCTION Limitations question #2
It worked for one cell. When I paste it down to the other cells I ge "#value!" error. I can't imagine having to set up a named range fo each row. I believe I set the correct format when I did the formula. Did it work for multiple rows of data for you -- rugby19999 ----------------------------------------------------------------------- rugby199993's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1578 View this thread: http://www.excelforum.com/showthread.php?threadid=27293 ...

There should be user defined fields on SOP lines
There should be user defined fields on SOP lines ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=4db900e2-549f-40d2-bc4d-f32e802109bd&dg=microsoft.public.greatplains I ...

Help understanding the functionality of the 'My Work' queue
Morning all, I am after an explanation of how the 'My Work' queue should behave. I have read through the Implementation Guide and looked at various sources on the internet but can only find information on setting up a new queue. We are using MS CRM 3.0 and have been passed a request to get users to check/use the My Work queue. The problem is we have had no real training on this side of CRM and dont really know if its functioning correctly in the first place. What are the critirea that an Email activity has to meet to end up in the users My work queue? Should it only e...

Function to escape arguments for an xpath / xquery expression?
Hi, I'm using MS Sql Server 2005. I have a clause in my query that looks like OR (sae.category_xml.exist('/categories/info_type/category/ @name[contains(.,"$keyword$")]') = 1) where "$keyword$" is replaced with the string I want to check. However, if that string contains a "&", the expression fails with an "Unknown entity reference" error. Does anyone know of a function I can use that will escape my string to substitute all the appropriate entity references? Thanks, - Dave On Wed, 18 Aug 2010 10:02:49 -0700 (PDT), la...

Excel Scrollbar not functioning
The scrollbar on one of 6 worksheets in an Excel program approximately 6MB in size mysteriously stopped working. I can no longer scroll down the page and when I try to do so the scroll bar moves but the page is idel. I developed the file on my hard drive and then transferred to a network through Citrix. I started having the problem on the network so I took it off but it is still happening now. Again, it only happens on the one worksheet but the other five are fine. Any ideas? Just one quick, simple diagnostic to try out on that worksheet .. Ensure that there's no pane frozen i...

EXPORT FUNCTIONALITY
Hi, I have read messages regarding disabling the export into excel functionality (basically removing the excel icon). However, is it possible to disable this on a user by user basis? As an administrator I want to be able to download leads/contacts/accounts but I do not want the users to be able to download our customer data. Thanks Lee disabling the excel icon is not enough. you would also have to stop the users running reports as well as they could get a copy of the customer data that way as well "Lee" <l.hargrave@btinternet.com> wrote in message news:394322d8.0406090008....

Beta Finance Function
Is there a function in Excel to determine beta for finance? John C. Harris wrote... >Is there a function in Excel to determine beta for finance? Excel provides both covariance, COVAR, and variance, VAR, functions, so with those and A LOT of corresponding historical market and individual asset returns you can calculate beta for those assets. beta is just the covariance of individual asset returns with the market return divided by the variance of the market return. So simple AS LONG AS YOU HAVE A LOT OF HISTORICAL RETURN STATISTICS. This is a data-driven problem, so easy to calculate aft...

How to pass a user defined Class to a dll
Hi, I need to pass a user defined class object to a dll and want to access it from there.How do i do it? Please help me Reny ...

Mail Merge Functionality in 3.0
I am told that customizing mail merge documents for MSCRM 1.2 is very limited. Example, you cannot add any desired additional fields on the mail merge template. My question is, in MSCRM 3.0 can this be done? Or do you still need to purchase a third party add on program? Thank you in advance for your help! ~Cayla hmmm sort of looks like you can use custom fields in everything apart from activities...I have not tried it yet...anyone care to comment? ========================= John O'Donnell Microsoft CRM MVP http://www.microsoft.com/businesssolutions/crm/community/microsoft_crm_co...

Hiding formula/functions
I received a spreadsheet that someone wants me to help them with. The vba code that runs when a button is clicked exports a range to a csv file. I entered the following formula into the first column so that it would enter a 1 only when something is entered into column N. This part works. =IF(N8<>"",1,"") However, when I know export the data it thinks it should export all 92 rows because it thinks the formula is part of the data. How do I tell the code to NOT include the formula when it searches for a blank row? Thanks, I am thinking there is...

Is there a RATE function for single sum?
Is there a built in function for calculating the interest rate for a single sum? IOW, is there a function to calculate i in PV =FV/(1+i)^n ? I can do the math to solve for i but I want to know if there is a function to do it for me. The RATE function is for annuities. NOMINAL and EFFCT each take the other as input. And there are several functions to calculate security yields given specific dates. But all I want is a function to calculate i for a single sum. Is there such a function? On Sat, 18 Aug 2007 13:10:09 -0700, "Dave" <davefrick@newsgroup.nospam> wrote: &g...

Exporting functions from my application
Hi, I know how to export functions from a DLL And I know how to use WM_COPYDATA to do a very simple IPC. But is it possible to export functions directly from the exe? What I am aiming to do is. 1- Start my main application 2- The main application would then start another exe 3- The 'other' exe would contact the main application to get needed information via some exposed API/Functions. Would the above be possible? Simon "Simon" <spambucket@example.com> ha scritto nel messaggio news:67lfdtF2p7l6uU1@mid.individual.net... > But is it possible to export functi...

Help with Camera Function
I'm trying to copy a picture of part of a spreadsheet into a Word document. The Camera function found in Tools\Customise\Commands\Tools almost does the trick but I particularly want to include the Row and Column headings so it's easy to refer to particular cells or ranges. Can Camera be used to show Row and Column headings as well as cells and, if so, how? If not, what is the easiest way of achieving what I want to do? Thanks a lot Hi Try Snagit for this http://www.techsmith.com/ -- Regards Ron de Bruin http://www.rondebruin.nl "nospaminlich" <nospaminlich@di...