Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-18-2013, 01:08 PM
Ulodesk Ulodesk is offline VBA is objecting (no pun intended) Windows 7 64bit VBA is objecting (no pun intended) Office 2010 64bit
Word 2013 Expert Cert
VBA is objecting (no pun intended)
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default VBA is objecting (no pun intended)

I copied from Greg Maxey's site a macro for inserting a section and unlinking the headers and footers.


http://gregmaxey.com/word_tip_pages/...k_headers.html
I pasted the macro at the bottom of my list of macros in VBA as I usually do, but VBA objected when I tried to save. As shown below, my last macro ends, then his begin with the four lines shown before his Sub line. There is no horizontal line sepArator until after the last of the four lines, before his Sub line.

End Sub

Option Explicit
Dim i As Long
Dim j As Long
Dim oDoc As Word.Document

Is this what is causing the problem? Is it easy to solve, or do I have to do soemthing with "option explicit" (whatever that is) to all my macros if I want to use this one? I have utterly failed in trying to teach myself VBA several times. I record or paste macros occasionally, as needed. I've never had this problem before.
Reply With Quote
  #2  
Old 06-18-2013, 02:21 PM
fumei fumei is offline VBA is objecting (no pun intended) Windows 7 64bit VBA is objecting (no pun intended) Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

1. Option Explicit should only be used onbce, and it should be at the very top (beginning).

2. Once you have other Subs in the module, declarations (Dim Blah as Yadda) should be IN a Sub - i.e within a Sub.....End Sub.

Public declarations (Dim Blah as Yadda) should be at the top, right after Option Explicit. I suspect that those declarations from Greg's site apply to the a Sub, and should be within the Sub.....End Sub.

Option Explicit in a module requires you to make declarations. This is a GOOD idea. You can have VBA insert it automatically for new modules by going Tools > Options and on the Editor tab check Require Variable Declaration.

So. Move Option Explicit to the top of the module. Move the declarations between a Sub and End Sub.
Reply With Quote
  #3  
Old 06-19-2013, 08:46 AM
Ulodesk Ulodesk is offline VBA is objecting (no pun intended) Windows 7 64bit VBA is objecting (no pun intended) Office 2010 64bit
Word 2013 Expert Cert
VBA is objecting (no pun intended)
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Thumbs up Solved!

Thank you. That did the trick.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA is objecting (no pun intended) "Your message did not reach some or all of the intended recipients." vektor Outlook 1 02-23-2011 07:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:02 PM.


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