Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2020, 11:48 AM
MikeatMSOffice MikeatMSOffice is offline Macro works at home but not at work Windows 10 Macro works at home but not at work Office 2019
Novice
Macro works at home but not at work
 
Join Date: Feb 2020
Posts: 3
MikeatMSOffice is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 02-07-2020, 06:59 PM
Guessed's Avatar
Guessed Guessed is offline Macro works at home but not at work Windows 10 Macro works at home but not at work Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 02-07-2020, 08:04 PM
MikeatMSOffice MikeatMSOffice is offline Macro works at home but not at work Windows 10 Macro works at home but not at work Office 2019
Novice
Macro works at home but not at work
 
Join Date: Feb 2020
Posts: 3
MikeatMSOffice is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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?

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.
Reply With Quote
  #4  
Old 02-09-2020, 06:12 PM
MikeatMSOffice MikeatMSOffice is offline Macro works at home but not at work Windows 10 Macro works at home but not at work Office 2019
Novice
Macro works at home but not at work
 
Join Date: Feb 2020
Posts: 3
MikeatMSOffice is on a distinguished road
Default

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro works at home but not at work Macro to Find and Replace Does Not Work - But Works Manually Rod_Bowyer Excel Programming 7 10-14-2018 11:49 PM
Macro works at home but not at work Using Onenote on Work and Home computers and on Android phone johnmccrady OneNote 1 12-27-2015 09:59 PM
Macro works at home but not at work Why won't up and down work like home and end anymore? Scythe Word 5 03-04-2015 12:32 PM
Macro works at home but not at work 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:08 AM.


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