Link to home
Start Free TrialLog in
Avatar of Richard Morris
Richard MorrisFlag for Canada

asked on

Microsoft Word 2007 Macro Runtime Error: 4248

I am working on the following macros I found online while searching Google two of which are fine AutoNew and AutoOpen but AutoExec is not working:

AutoExec does not work when using the MS Word 2007 shortcut icon on the quick launch area of my taskbar because it says the page is not open yet, this makes no sense to me but must be fixed:

Sub AutoExec()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub

The AutoNew macro works fine for creating new docs when MS Word 2007 is already open:

Sub AutoNew()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub

The AutoOpen macro works fine for opening docs already created with MS Word 2007:

Sub AutoOpen()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub

To recap:

a) I can open MS Word 2007 docs already made and the macro works fine.

b) I can create new blank docs when MS Word 2007 is already open and the macro works fine.

c) I can NOT create new blank docs using the MS Word 2007 shortcut icon on my taskbar’s quick launch area.

Summary overview:

I need the ability to create new blank docs using the MS Word 2007 shortcut icon on my taskbar’s quick launch area to behave the same as opening docs that MS Word 2007 already created and creating new black docs from within MS Word 2007.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

The message means what it says. The default blank document is not created until Autoexec has finished.

Open the Normal template, and make sure that it is set to the View that your macro tries to achieve, save it and close Word. When Word reopens the default blank document will have that View.

These are very old macros -- for some Word versions now, you should use events of the This Document class module instead of an AutoNew macro.  For example, use the Document_New event procedure for code to run when a new document is created.  Similarly for the Document_Open event.
Avatar of Richard Morris

ASKER

Hello GrahamSkan,

If the default blank document is not created until AutoExec is finished, what are we going to do exactly in order to resolve this problem?

I opened the normal template and see it is set to 100% however I can’t find where to set my page column to one.

Thus I need to be able to set the page column in Microsoft Word 2007 to one in my default blank document template but do not know how to do it.

The reason why I need to set the page column to one is because I have many more pages to the right of my document which makes it very hard to use Microsoft Word 2007 due to the fact I have a large monitor and I cannot change the screen resolution as this is the correct resolution for everything else I use on this computer.

I tried doing a Google search to change the page column to one but all it talks about is the columns in the document, not the pages of columns in my Microsoft Office 2007 window so I really need to know how to change this to one page per screen with a zoom of 100% as it is very important I can see what my page looks like with no zooming going on.

To recap:

How do I change the default blank document to show one page per window with a zoom of 100% keeping in mind I have it zoomed at 100% already so I only need to know how to see one page per window without changing the zoom of 100% I already have established.
Hello Helen_Feddema,

I found the macros online at a forum with a timestamp of 04-15-2011, 06:13 AM so I assumed they were current.

My Microsoft Word version is 2007 to be exact.

How do I use events of the This Document class module instead of an AutoNew macro?

Again, how do I use the Document_New or Document_Open event procedure for code to run when a new document is created?

And will doing any of what you speak of solve my problem above of needing to see one page per screen with a zoom of 100% or is this simply a general code tweak that really doesn’t solve my current problem?

Regardless I’ll try your code out if you tell me how to use it in order to see if any improvements are made as a result of your new coding style.
Try waiting a second, and then set the view parameters.
Sub Autoexec()
    Application.OnTime DateAdd("s", 1, "Now"), "SetView"
End Sub

Sub SetView()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub

Open in new window

Hello GrahamSkan,

I tried your macro and got a runtime error mismatch.

Does the macro work on your end?

The macro will not work for me on my end at all, please help.
Sorry, some quotes had crept in around the Now function

It should be:

Sub Autoexec()
    Application.OnTime DateAdd("s", 1, Now), "SetView"
End Sub

There seems to be a few bugs with it which are:

a) There is a 1 second delay on load up for my page to be listed as one column only on my screen, should be “real-time” as it is very annoying watching my page center after 1 second every time I load up a new document from my quick launch on my windows taskbar.

b) When I go to open a second document using my MS Word shortcut icon on my taskbar under quick launch, example Document2 the macro doesn’t work at all, it only works for Document1 only with a very annoying 1 second delay.

Also what is the Document_New code all about, will that make the macro work better or is that something I don’t need to think about since I’m not a VB programmer to start with so I really do not know anything about this and require help to get this running properly.
Hmm.

You should know that Microsoft lost enthusiasm for Auto macros when the Document_New and Document_Open events became available, and no longer officially promote them

The one second delay that I suggested is to allow time for the default document to load. If that time doesn't suit you, try shortening it to, say .5 of a second until you find a time that is long enough to work consistently, and short enough to be acceptable to you in your circumstances.
I will try to reproduce your second query about  a second document.

The Document_New event is the way that Microsoft now supports as the way of  initiating code when a new document is created, as opposed to Autonew, whose functionality could be abandoned in future.
Hello GrahamSkan,

Does this mean my macros should include Document_New and Document_Open events?

I changed the macro to .1 of a second but I can still see the page centering, is there any way to make the macro run in real time?

And why won’t Document2 run the macro when using the quick launch shortcut button on my windows taskbar?

Here is the macro I have so far:

Sub AutoExec()
    Application.OnTime DateAdd("s", 0.1, Now), "SetView"
End Sub

Sub SetView()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub

Sub AutoNew()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub

Sub AutoOpen()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub
Currently, putting the code into the Document _New and Document _Open events of the Normal template, as well as the Auto macros, wouldn't hurt (except for an unnoticeable delay because both routines will be executed).
I don't understand  'real time' in this context. My suggestion is simply a workaround for the fact that Autonew runs and finishes before the default document is loaded.
Hello GrahamSkan,

Can you show me how to do what you just described as I’m not a VB developer, just a MS Word 2007 user is all.
Hello GrahamSkan,

Real-time means zero delay, see my AutoNew and AutoOpen macros have zero delay but my AutoExec has a delay of 0.1 which to me seems like a patch solution rather than a full solution as I don’t like to wait even 0.1 of a second for something to happen, just seems too patchy for my personal taste.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello GrahamSkan,

I see the delay in the AutoExec macro is now gone, good work.

I’m still not clear about my macros needing to have Document_New and Document_Open events?

And why won’t Document2 and so on run the macro when using the quick launch shortcut button on my windows taskbar?

Here is what I have so far, let me know what you think about these macros:

Sub AutoExec()
    Dim doc As Document
    Set doc = Documents.Add
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub

Sub AutoNew()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub

Sub AutoOpen()
With ActiveWindow
  'Resizes to 100% and 1 page viewed
  With .ActivePane.View.Zoom
    .PageColumns = 1
    .Percentage = 100
  End With
End With
End Sub
As far as I know, in all current releases the operation of the Auto macros is not distinguishable from the Document_ equivalents, so use either. I tend to use the latter because it fits in better with the way that VBA in Word was developing from its forerunner (WordBasic). I'm sorry to have troubled you with such a geeky intervention.

I will have to research the 'quick launch' problem.



Unfortunately under the Windows7 OS that I am using, there isn't a Quick Launch Toolbar.

Is it possible to right-click on the icon and select properties to get the shortcut details to find out what it is doing?
Hello GrahamSkan,

So what Helen_Feddema said about the fact I should use Document_New and Document_Open events I can just ignore as a frivolous comment she made to me with no real bearing?

I find your explanations very good and glad to know I can keep using my Auto macros since I really don’t know how to use the newer Document_ equivalents anyways since I’m not a Visual Basic programmer.
Hello GrahamSkan,

The problem with my AutoExec macro not working when I open a second document with the Quick Launch Toolbar also takes place when I click on a MS Word 2007 shortcut icon on my desktop or the MS Word 2007 shortcut icon located in my windows start button menu area.

I do not think right clicking on the MS Word 2007 quick launch icon will matter since there are two other ways you can use to recreate the error and test to see why it is happening, thanks.
Hmm,

It wasn't a frivolous comment. In fact I thought that I had made it myself; hence my apology.

However, one of the three macros didn't work at all, so their source wasn't 100% reliable. The fact that the technique has been deprecated was worth a mention.

The Document_ macros would have the same code, but different names and in the ThisDocument module.

I haven't yet been able to reproduce your quick launch problem, but I'll dig out an old laptop with Windows and Office 2000 on it and see what that does.
OK. They laptop is actually running Office 2003 under Windows XP, but I still can't reproduce the problem.

Perhaps I'm not clear on what I am looking for. Why do you mention Document2? However Word is started it should open with Document1.

What method(s) are you using to start Word when it does work?
If you right-click on the Quick Launch icon, you should see Properties in the pop-up. This should open the Properties dialogue.

Can you tell us what is in the Target box on the Shortcut tab, please?
Hello GrahamSkan,

Maybe I should upgrade to Document_ macros then?

How do I add different names in the ThisDocument module?
Hello GrahamSkan,

My problem is in MS Office 2007 under Windows Vista.

I mentioned Document2 because Document1 always opens properly when I use the quick launch, start menu or desktop shortcut, however Docuement2 always fails assuming Docuement1 is still open otherwise it would just open another copy of Document1 again.

My MS Word 2007 does start with Documenrt1, I mean when I click the quick launch button, start menu or desktop shortcut twice in a row, the Document2 fails, however Docuement1 is fine.

My MS Word 2007 always works for Docuement1 from the quick launch, start menu and desktop shortcut, it is Doceument2 that does not work, has nothing to do with Documents1 which works just fine for me with the macros I currently have.
Hello GrahamSkan,

My target box lists: Microsoft Office Basic 2007

Microsoft Office Basic 2007 includes Word, Excel and Outlook, not to be confused with Microsoft Office Starter 2010 which is something totally different than what I have.
The macro with which we are having problems in the AutoExec, for which there is no Document event equivalent, so changing the other two macros is unlikely to help.

I'm not familiar that quick launch shortcut. How does it know that you want a new Word document, as opposed to a spreadsheet or a database?
Hello GrahamSkan,

Oh, so there is no Document even equivalent for AutoExec? I figured Helen_Feddema was wasting our time with her comment that does nothing to solve our problem at hand, thank you for pointing that fact out to me.

I only have Word, Excel and Outlook, for some reason my quick launch shortcut, start menu shortcut and desktop shortcut list Microsoft Office Basic 2007 as the target, however the font is in light gray which means I cannot edit the target, maybe that has something to do with it?

Now my Outlook shortcut does point to a regular target which is: "C:\Program Files (x86)\Microsoft Office\Office12\OUTLOOK.EXE"  /recycle

Perhaps that will help you figure out the MS Word 2007 equivalent target as I’m sure they must be similar.

I looked at this a bit more, the Word shortcut is a system shortcut, whereas the Outlook shortcut is a user shortcut, so they are a bit different is why the target is grayed out on system shortcuts and not on user shortcuts.
Please start from the principle that we are all trying to help. We are all volunteers and get no payment for contributing here.

I am trying to find out what the shortcut does when it opens Word. You report that the target is 'Office'. Therefore you must do something after that to open a new or an existing Word document and not anything else in the Office suite. Can you describe those actions, please?
Hello GrahamSkan,

Okay, so you believe we should let Helen_Feddema off the hook for making a miscellaneous statement? If you think that is the best course of action in regards to Helen_Feddema then I’ll agree with you on it.

No, the target is “Microsoft Office Basic 2007” not just “Office” okay.

When I click the “Microsoft Office Basic 2007” target I go immediately to Document1 in MS Word 2007, there are no other steps or delays because it is instant faster than a blink of an eye.

When I click on the “Microsoft Office Basic 2007” target again when Document1 is still open my AutoExec macro fails me in Document2, please help me correct this problem.
Perhaps you could try making a new shortcut, to open Word explicitly, and see if that makes a difference.  To do that, right-drag the WINWORD.EXE file to your desktop, and select Shortcut from the context menu -- or create a new shortcut and type it in path as its target.  On my Office 2003 system, the path is "F:\Microsoft Office 2003\OFFICE11\WINWORD.EXE"
For Office 2007, the path would be different, such as "C:\Progam Files\Microsoft Office\Office 12\1033".
Sorry, cut the \1033 -- the final path is just Office 12
Generally speaking, code that used to be in an AutoExec macro can be (since Word 97 at least) put into either the Document_New or Document_Open event, depending on whether you want it to run when a new document is created from a template, or when an existing document is opened.  Since your AutoExec macro includes a Documents.Add line, the code (minus that line) could be put into the Document_New event procedure, either for the Normal.dot template or a custom template.
If you are not sure where WINWORD.EXE is located, open a Word 2007 document, click the big Ofice button and then the Word Options button, go to the bottom of the Advanced screen and click the File Locations button.  The Tools line shows the Office path.
OK. 'Office' was an abbreviation for what you see. The icon doesn't seem to specify which application you need to use, so I assume that there is a subsequent step in which you give those details.

Do you use the same icon for any other Office applications (Excel, Access, Outlook, Publisher, Powerpoint. etc)


 
Helen,

Can you help on what the Office quick launch shortcut does?
Hello Helen_Feddema,

I already tried making a new MS Word 2007 shortcut on my desktop but the target was still “Microsoft Office Basic 2007” rather than a link.

If I go through my Windows Explorer to manually look for WINWORD.EXE here is the location it is at:

C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.EXE
Hello Helen_Feddema,

I am using my macros for new docs and opening docs both.

You want to convert my AutoExec into a Document_New and Document_Open event for me?

I am using this for the Normal.dot template.

Okay on making a Document_New event procedure just as long as it works.
Hello GrahamSkan,

There is no subsequent step.

Like I said before, I only have Word, Excel and Outlook on this computer and that is all.

I do not use my MS Word 2007 shortcut for any other programs, not a chance.
Do you use the same icon to open an Excel spreadsheet?
Hello GrahamSkan,

Here is what I use for my three office programs I have:

Microsoft Office Word 2007 target: Microsoft Office Basic 2007 (blue icon)

Microsoft Office Excel 2007 target: Microsoft Office Basic 2007 (green icon)

Microsoft Office Outlook 2007 target: Microsoft Office Basic 2007 (orange icon)

As you can see I use three totally different icons for three totally different programs with the same target, hope that makes sense to you.
Gottit.

It's my limited imagination. At one time there was an Office Toolbar, so when you said the the target was 'Microsoft Office Basic 2007' rather than Microsoft Word, that's what I thought we were dealing with.

Also it has never occurred to me that the Word shortcut would be used when the application is already open, as opposed to opening a new document from within the application.

Unfortunately, none of the five macros run when you do that.

However, the initial View settings for new documents are taken from the template, so it shouldn't be necessary to change them with a macro.
Hello GrahamSkan,

I use the MS Word shortcut when MS Word is already open continually for over 10 years now, that’s how I do it, faster than going into the Office Button by a lot.

Why do the macros not run when I do that?

So you know how to set the page column in the MS Word pane to one so I only see one page at 100% zoom simply by using the normal template?

How do you do it, if I could do that I wouldn’t even need macros at all, that’s for sure.
It's just me, then.

It is somewhere in the design of  Word.

As we know, AutoExec runs when Word is opened and AutoNew runs when a user, or VBA, creates a new document. Neither happens here.

I opened the Normal template and modified the view settings to what we don't want as a way of testing these macros, so that I could see the effect. All you have to to is to open the template and set the view to your requirements and save it again, as I suggested in comment #36493912.
Hello GrahamSkan,

I already read your suggestion and replied back stating I need to set the column too, how do you set the column to one in the normal template?

I do not mean the document columns either because I mean the page columns I see in my MS Word 2007 panel.

I have a widescreen and can see numerous pages in one screen, thus I need those columns down to one only.

How do I bring the columns down to one only using the normal template as I could not find any such option but then again I’m not a pro with MS Word 2007 either, so please tell me where to look for this mystery setting that I cannot locate in my normal template?
If you open Normal.dot and set the columns (and any other properties, such as default font and size) as you wish), then close and save the template, when you make a new document it should have those properties.

Did you make a shortcut for Word by right-dragging WINWORD.EXE to your desktop, or by creating a new blank shortcut as a new object from the desktop context menu, and then entering the path as its target?
Graham -- In some older versions of Word, I recall that there was an Office Document (or some such name) shortcut on the Start Menu.  Maybe this is the one that was previously opening a new Word document.  Perhaps Word was the default document type.  However, I think this shortcut was dropped at some point (that happens from time to time), so maybe that is why it isn't working now.
I remember the Office Shortcut Bar with fondness -- when It was pulled, I created a more or less similar toolbar to open off the Taskbar (for Office 2003/2007).  Now, though, in Office 2010/Windows 7, the new taskbar functionality offers lots more functionality, so I don't miss it so much.  And of course you can put a big Word (or Excel) icon right on the taskbar, which creates a new Word doc when clicked.  What version of Windows are you running?  If you have Windows 7, just right-click the Word item in the Start menu, and select Pin to Taskbar, to create this icon.
Hello Helen_Feddema,

How do you make the page columns?

I already told you I know how to make document columns, it is the pages that are the problem, I only want one column of pages per window.

I already made a shortcut on my desktop for WINWORD.EXE and it still has the same target which is: Microsoft Office Basic 2007

Please read the previous posts, both statements were already answered in the thread above.
Hello Helen_Feddema,

Regarding your message to GrahamSkan, I want you to know I have Microsoft Office 2007 and there is no Office Toolbar/Shortcut Bar on my computer, only the three icons, one for Word, one for Excel and one for Outlook, they are not linked together in any fashion other than their targets are the same but that has to do with Microsoft and nothing to do with an Office Toolbar/Shortcut Bar which this computer does not have.
Hello Helen_Feddema,

As I already said I’m on Windows Vista and I use Office 2007.

Also if possible, please make your posts as one post instead of three, makes it easier for me and others following this thread to read that way rather than having to reply three separate times to something that could have been said in a single post, thank you.
I'm not sure if we have said it explicitly anywhere, but the PageColumns setting represents the number of pages that can be seen in the window, so setting it to 1 is the same as clicking the 'One Page' button in the Zoom group on th View tab.
I recommend trying one of my suggestions above, namely opening Normal.dot (as a template), and setting it as you wish, then closing and saving it.  This should ensure that new documents will have the same settings.
Hello GrahamSkan,

Where do I find the PageColumns setting so I can set it to one?
Hello Helen_Feddema,

When I open the Normal.dot (as a template), where do I go to find the PageColumns setting so I can set it to one?
You set if from the Zoom group on the View window. You can choose One Page, Two Pages or, on the Zoom dialogue, Many pages.
Hello GrahamSkan,

I am in the Zoom group on the View ribbon.

One page puts me at an 85% zoom is the problem!!!

If I zoom up to say 90% I end up with two columns of pages instead of one.

How do I zoom to 100% with one page column?
Does the 100% button help?
Hello GrahamSkan,

Of course the 100% button does not help.

The 100% button will undo the One Page button and the One Page button will undo the 100% button.

What I really need is for both buttons to work together!!!
On my system, the One Page button does what it says on the tin, and sets the size so that the whole page can be seen. The 100% button increases the display size of the page, so not all of it can be seen. This matches exactly what the macro code does.

    .PageColumns = 1 'One Page button
    .Percentage = 100 '100% button
Hello GrahamSkan,

The One Page button and 100% button will not work together at the same time on my system, please help.
Here are some pictures.

Starting with a two-page view:
User generated image

We click on the One Page button:
User generated image
And then set the size to 100%:
User generated image
Hello GrahamSkan,

I clicked on the One Page button which puts me at 85% page zoom.

Then I click on the 100% button and then I’m back to two pages.

Please help.
I tried the same thing (in my Word 2007 VM), and I got the same results as Graham -- clicking on One Page button went to a smaller Zoom factor (on this screen, 71%), and then when I clicked 100% the Zoom increased to 100%, without going to two pages.

There may be something amiss with your Office setup -- it is probably worthwhile to run Office Repair and see if it fixes some of the problems you are having.  To do this, open the Add/Remove Programs applet in the Control Panel, select your version of Office, click the Change button, and then select the Repair option in the dialog that opens, and click Continue.
Have you tried clicking the 100% option on the Zoom dialogue?
Hello Helen_Feddema,

I clicked on the One Page button and went to a smaller Zoom factor (on this screen, 85%), and then when I clicked the 100% button the Zoom increased to 100%, but went to two pages.

I believe my office setup is okay because I read about other people not being able to make this work in Office 2007 but I think it was fixed for Office 2010.

Are there any other workarounds?
Hello GrahamSkan,

Yes, I clicked the 100% option on the Zoom dialogue and it put me back at two pages again!

Then when I click the One Page button it puts me down to 85% zoom, then I click the 100% button and then I’m right back to two pages again, help!
Is your Word window maximized or restored?  If it is maximized, try restoring it and see if that fixes the problem.
Hello Helen_Feddema,

No, restoring MS Word down doesn’t fix the problem at all plus I want my MS Word window maximized so even if it did fix the problem it wouldn’t be what I wanted because I only like to work with my windows maximized.
It does sound to me as if your Word application is not operating properly. Here is a list of troubleshooting steps from Microsoft that you could try.

http://support.microsoft.com/kb/921541
Hello GrahamSkan,

I do not believe I need to troubleshoot my copy of MS Word 2007 and here is why:

You are testing from MS Word 2010 which corrected the issue MS Word 2007 had.

So what is the point in troubleshooting if that is how it was made in the first place?

I will accept your macro as the solution, albeit not a flawless solution, it is at least acceptable.

I’ll await your response in case there is anything else you would like to add before I accept your macro solution as the final solution to the MS Word 2007 one page column per window at 100% zoom issue.

Your assistant Helen_Feddema will not get any points as you were the one who made the macro for me all by yourself, thus I will give you all 500 points okay.
Expert user GrahamSkan was very wonderful to work with, knowledgeable and timely. I highly recommend working with GrahamSkan in the future most definitely. You won’t be disappointed because he has the uncanny ability to solve any problem set before him with the utmost of ease.

Thank you for everything, you have made my life a whole lot better thanks to your advanced skills and keen willingness to help even when the problem at hand seems too large to overcome, you always find away to pull through and get it done, you truly have been a genuine joy to work with.