Procedure Too Large - Seperate functions

Helen Pippard

New Member
Joined
Dec 12, 2008
Messages
47
Hello,

I have a Function in VBA which is "too large" to run

So what I have done is taken a huge chunk of the procedure and created a seperate function which I need to CALL back into my main function

The original syntex read as:

m_objDoc.Bookmarks("COUNT_DPED_COLECTOMY").Select
m_objWord.Selection.Text = Switch(IsNull(DLookup("[COUNT]", "COUNT_DPED_COLECTOMY")) = True, "", True, Round(DLookup("[COUNT]", "COUNT_DPED_COLECTOMY")))

This took a value from a table and exported the data into my bookmark in MS.word, but as I am repeating this process over 100 times the procedure became too large

I created a new function called:
SetVariablesForSwitch(StrVariable As String)

In this function I declared my variables and did all the switch statements

Now I do not know how to CALL the function correctly in my main function. I currently have it set as

m_objDoc.Bookmarks("COUNT_DPED_COLECTOMY").Select
m_objWord.Selection.Text = StrVariable = SetVariablesForSwitch("StrCOUNT_DPED_COLECTOMY")

All this returns is a TRUE in my word document.

Question

I need to know what correct VBA to use in order to call my sub funtion correctly and so it can recognise that what I am calling is a variable and I want it to export the value into my bookmark in MS.word

Any suggestions?

Thanks for any help?

Helen
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I'd look at this line
Code:
m_objWord.Selection.Text = StrVariable = SetVariablesForSwitch("StrCOUNT_DPED_COLECTOMY")

What you're doing is using two = operators which logically is setting your .Text property to whether the StrVariable = SetVariblesForSwitch... is True or Not.

Try this
Code:
m_objWord.Selection.Text = SetVariablesForSwitch("StrCOUNT_DPED_COLECTOMY")

Also shouldn't your strVariable be used somehow, perhaps like
m_objWord.Selection.Text = SetVariablesForSwitch(StrVariable). Or not, not sure what the strvariable is in there for.

hth,

Rich
 
Upvote 0
Hello,

Thank you for your help!

Yesturday afternoon I had a break through, with a little bit of help from a colleague of mine.

In my sub function I have the following code for each of my options

Select Case StrVariable
Case "StrCOUNT_DPED_COLECTOMY"
SetVariablesForSwitchX = Switch(IsNull(DLookup("[COUNT]", "COUNT_DPED_COLECTOMY")) = True, "", True, Round(DLookup("[COUNT]", "COUNT_DPED_COLECTOMY")))
Case Else

End Select


In the Main function I call the sub function by:

m_objDoc.Bookmarks("COUNT_DPED_COLECTOMY").Select
m_objWord.Selection.Text = SetVariablesForSwitchX("StrCOUNT_DPED_COLECTOMY")

As you kindly suggested

My Main Function and sub function now work perfectly

Thanks for your input

Helen
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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