#1
|
|||
|
|||
Macro works at home but not at work
Hi All. This is my first post here.
I'm having trouble with a macro working on my home machine but not on my work machine. My home machine runs MS Office Home and Student 2013 on Windows 10 Pro v 1903. My work machine runs MS Office 365 ProPlus on Windows 10 Pro v 1909. As far as I can tell the dotm file on both machines is exactly the same. There is nothing in the Normal.dotm on both machines when I look at the Developer/Visual Basic enviroment. The Macro Security options on both machines seem to have the same settings. So now I'm beginning to think it may be an issue with an update. They were both working until a recent MS Office update at work. The macro giving me trouble follows. This macro is meant to center a form field when it is selected. That way, I don't have to use the mouse to keep the selected field in view. I'm trying to design a macro enabled test form for my company. Any advice on how to remedy or diagnose the problem would be a great help. Thanks. Public Sub SelectionScrollIntoMiddleOfView() AltS = False Dim pLeft As Long Dim pTop As Long, lTop As Long, wTop As Long Dim pWidth As Long Dim pHeight As Long, wHeight As Long Dim Direction As Integer wHeight = PixelsToPoints(ActiveWindow.Height, True) ActiveWindow.GetPoint pLeft, wTop, pWidth, pHeight, ActiveWindow ActiveWindow.GetPoint pLeft, pTop, pWidth, pHeight, Selection.Range Direction = Sgn((pTop + pHeight / 2) - (wTop + wHeight / 2)) Do While Sgn((pTop + pHeight / 2) - (wTop + wHeight / 2)) = Direction And (lTop <> pTop) ActiveWindow.SmallScroll Direction lTop = pTop ActiveWindow.GetPoint pLeft, pTop, pWidth, pHeight, Selection.Range Loop End Sub Last edited by MikeatMSOffice; 02-07-2020 at 03:05 PM. |
#2
|
||||
|
||||
Are you saying the document event is not firing or the code is producing an error?
If it is an error, what line is failing and what error message are you seeing? What is AltS used for and why is it undefined?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Quote:
AltS is used to indicate that the Alt + S keys have been pressed to run a macro that sets AltS to true to allow escape from showing the Msgbox declaring that tolerances have been exceeded. Otherwise I cannot scroll somewhere else because the tolerance msgbox scrolls me back to the field that's out of tolerance. AltS is Dim'd and set to false somewhere else. I run the SelectionScrollIntoMiddleOfView() macro on Entry of the form fields to center the field when it is selected. At home the macro works. But at work it simply scrolls to the top of the document and stays there, no matter which field is chosen. No error messages are shown. I think I need to start printing out all the variables in a Msgbox to see the differences between work and home. Or maybe I need to role back the Office updates to see if it starts working again. Thanks. Last edited by MikeatMSOffice; 02-08-2020 at 08:59 AM. |
#4
|
|||
|
|||
Since the document continues to scroll to the top when I click on a field that runs SelectionScrollIntoMiddleOfView() on Entry, it seems the ActiveWindow.SmallScroll Direction inside the Do Loop is being executed. But the scrolling is not stopping when it is supposed to. So I suspect the conditional statements of the Do Loop are not being evaluated correctly. Let me put some parenthesis in the conditional statement to see if it evaluates correctly. I'll let you know.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to Find and Replace Does Not Work - But Works Manually | Rod_Bowyer | Excel Programming | 7 | 10-14-2018 11:49 PM |
Using Onenote on Work and Home computers and on Android phone | johnmccrady | OneNote | 1 | 12-27-2015 09:59 PM |
Why won't up and down work like home and end anymore? | Scythe | Word | 5 | 03-04-2015 12:32 PM |
work vs regular work. and how regular work works | user0044 | Project | 5 | 03-06-2012 07:28 AM |
Ctrl+Home no longer works to get me to beginning of doc. | migdaw01 | Word | 0 | 01-13-2011 12:11 PM |