VBA macro to control cursor within Word - vba

I normally use VBA within Excel but this time I need something for Word.
I want to be able to keep the cursor on a particular line within the screen by scrolling the document rather than moving the cursor.
Is there an event I can trap, or is there a function that can be written, which scrolls the document up rather than moving the cursor down, when typing would normally move it to the next line?
Instead of UpArrow, DnArrow, PgUp, PgDn, etc. moving the cursor in the standard direction, scrolling the document in the opposite direction to achieve the same effect but to leave the cursor on the same line of the screen.

Related

How do I focus Word document after using userform in VBA?

I have a small userform as interface to various VBA functions. I use these commonly for document automation like inserting tables formatted in certain way etc.
This works great, but I would like to have a workflow where I place the cursor at desired place, click the function, and can continue writing. Currently the form always keeps the focus after being clicked. The form is not modal.
So in image below, I have focus on (1) but want focus on (2) after VBA sub in form has completed.
I did try ending the macro with ActiveDocument.ActiveWindow.SetFocus which does not make a difference.
I could of course close the form after every macro, but I use it commonly, so this would be less preferred.
Please, try one of the two ways. Both of them have to work:
Word.Application.Activate
AppActivate ActiveDocument.ActiveWindow.Caption

Word 365 Markup/final view UI display problems

Because of lockdown measures, I've recently begun working from home. I work for an editing company, and I'm required to do a lot of reviewing of editor work (in addition to editing, re-editing). This requires me to quickly and frequently toggle between markup (tracked changes) view and final view. I have hotkey macros to do this, but unlike my 2016 version at my office, Word 365 does not retain the current position when I toggle views, but instead it (the display) jumps to the same page on the other view (the cursor does remain), making it so I lose my place and have to spend seconds finding it again. I need to be able to quickly toggle while keeping my eyes fixed on the current cursor position. I've adjusted my macro so it still keeps the cursor on the page, but it nevertheless jumps around within the page. I need the cursor and its displayed position on the page to remain fixed when switching views.
A secondary problem related to this is that when I select words in final view to comment on (or to edit/replace/highlight/etc.), these words are not actually selected as it jumps to markup view (instead seemingly just selecting the one single next word).
This may not be the appropriate place for a question like this, but I didn't know if some finagling with VBA might help me out here or maybe there were just some people with more Office expertise.
Thanks for any help!
Here is my macro. It's extremely basic, and I just did it from "record macro"; I've done very little actual VBA coding. I believe this is equivalent to clicking "all markup" and then pressing CTRL+RightArrow. The ones to show the final and original text are the same except for the .markUp.
Ideally, I wouldn't need any code because it would just be some setting I'm not aware of, but I know they love to change the fundamentals of how staple programs like Word operate between versions just to mess with people.
Sub markUp()
'
' markUp Macro
'
'
With ActiveWindow.View.RevisionsFilter
.markUp = wdRevisionsMarkupAll
.View = wdRevisionsViewFinal
End With
Selection.MoveRight Unit:=wdWord, Count:=1
End Sub

PowerPoint VBA code not running unless VB editor opened first

I have a PowerPoint presentation which consists of a single slide and some VBA code. The code displays a dialog box (not inside the presentation) which configures the slide.
I need the code to be started when the presentation is started.
I found various suggestions and ended up going with
this one however I am getting inconsistent results!
If I do the following, in sequence, it works:
Open presentation in PowerPoint
Select Developer tab
Select Visual Basic (to open VBA editor)
Close VBA editor
Select Slide Show tab
Select From Beginning
However, if I skip steps 2-4, it does not! I.E.:
1. Open presentation in PowerPoint
2. Select Slide Show tab
3. Select From Beginning
It is almost as though Visual Basic support isn't even loading until the editor is opened.
I also tried adding a slide before my main one with an auto-transition immediately and again, no-go.
This is driving me insane as I need to get this deployed to the rest of my department.
Anyone have any ideas?
It's kind of a known problem.
OnSlideShowPageChange sometimes doesn't fire. To get around it, add any of the Active-X controls from the Developer tab to the first slide. Scoot it off the slide if you don't want it visible.
Somehow the control forces VBA to initialize, so events fire.
After I did this with your presentation, it fired off right away.

VBA script to insert anchor position for autoshapes in Microsoft Word 2007

I'm beyond the limits of my kindergarten-level VBA skills so would like to ask if anyone here can help me write a VBA script to help me work stepwise through my Word document and adjust the anchoring position of all the AutoShapes in the document.
I have a 400-page book in Microsoft Word with at least one and sometimes several marginalia (sidenote) on each page in a thin column to the left of the main body text column. These sidenotes are a concise 'pointer' to a particular point made in the body text and need to appear directly to that point's left.
Each sidenote is in its own AutoShape (within a textbox in that shape). The AutoShapes were placed by the author in an inconsistent way. Mostly they are anchored to a position on the page.
However, I need to repaginate. This will cause the body text to flow differently and I need the sidenotes to flow with it (approximately or exactly)!
So before I repaginate I want to make sure I anchor each AutoShape to the paragraph it belongs to and not to the page it is currently on.
I don't know if that can be done automatically, since I don't know how Word could deduce a purely spatial relationship between an AutoShape and a paragraph.
So I'm guessing I have to make do with a "semi-automatic" process. Something like this:
Press a button to start VBA script
Select next AutoShape
Prompt for user to enter cursor in body text where anchor is to be placed
Resume macro
Place anchor for that AutoShape in that position
Change vertical position paramater of AutoShape to "relative to paragraph"
and "0 mm"
(Alternative, not 0 mm but another value deduced to more
accurately position AutoShape)
Change width parameter of AutoShape to
a particular fixed value 37 mm (some of them were a little
inaccurately drawn)
End cycle and go back to beginning to
Select next AutoShape
Hope that is all understandable.
I've tried to record a VBA script to do some of this but have no idea how to build in the user prompt.
Any help much appreciated!
Craig
You may be better off creating a macro that works on one shape at a time, or anchor all the shapes manually (which you're almost doing anyway) and then write a macro to take care of the various parameters and settings you want.
If you really want to prompt the user while the macro is running you'll need to look into modeless dialogs (not possible on the Mac). See this link: http://www.bettersolutions.com/vba/VXV113/SE846743531.htm
Basically, you'd have to create your own dialog and then show it modelessly so that the user could still place the cursor before hitting OK. If you're new to VBA, this could be difficult to set up.
While searching for solutions to this, I found a post on another forum from someone trying to do something very similar. He was developing a set of tools for editors using Word and until I find the ultimate solution I am using his "Shapes" tool which allows me to change parameters on each AutoShape I select at-a-click instead of opening up and closing a dialogue box each time, plus selecting a different tab each time... His tools can be downloaded at his Editors' Toolkit website.

Copy and paste board

Idea:
Have a window that is always on top.
Inside the window there are 10/20 text fields.
You can edit the fields in each individual box.
Once defined they become buttons.
When you click on a button it simply copies the text to clipboard.
When you click on a different button it copies that text instead.
Not overly complicated but is there anything like this that exists?
If not how difficult can a 0experiance coder make this?
can be done like this:
open a new excel sheet, make the window on top, enter lines you want to use, bring windowsize down until only cells are shown with text you want to paste.
if you want to paste text in another window: select cell, move cusror to border of cell until move cursor emerges, drag and drop.