Tuesday, August 9, 2022
  • PRESS RELEASE
  • ADVERTISE
  • CONTACT
Now And Then News
No Result
View All Result
  • Login
  • Home
  • National
  • International
  • Politics
  • Defense
  • Business
  • Health
  • Sports
  • Technology
  • Entertainment
  • Lifestyle
  • Travel
  • Home
  • National
  • International
  • Politics
  • Defense
  • Business
  • Health
  • Sports
  • Technology
  • Entertainment
  • Lifestyle
  • Travel
No Result
View All Result
Now And Then News
No Result
View All Result
Home Technology

How to use VBA to select and delete a single page in Word

by admin
June 24, 2022
Reading Time: 7 mins read
0
Share on FacebookShare on TwitterShare on email


Microsoft Phrase doesn’t provide a fast click on choice possibility for choosing and deleting pages. Use this VBA process to pick a particular web page and delete it.

Starting microsoft word application
Picture: PixieMe/Adobe Inventory

The article How you can use a VBA process that deletes the present web page in a Phrase doc reveals you how you can use a VBA process to delete the present Microsoft Phrase web page. It’s helpful if you happen to’re on the web page you wish to delete. When you must choose the web page earlier than deleting, you’ll want a bit extra code.

On this tutorial, I’ll present you a easy VBA process that prompts a web page quantity from the consumer after which deletes it. Subsequently, you don’t should be on the web page you delete — you will be wherever within the doc.

I’m utilizing Microsoft 365 on a Home windows 10 64-bit system, however you need to use older variations. Phrase for the online doesn’t assist VBA macros.

SEE: Home windows, Linux, and Mac instructions everybody must know (free PDF) (TechRepublic)

How the VBA macro works in Phrase

The process in Code A declares and defines a couple of variables earlier than prompting for a web page quantity from the consumer with an InputBox() assertion. The code saves the consumer enter worth to the pge variable. The second Set assertion selects the web page recognized by pge. The subsequent assertion makes use of a particular bookmark to pick your entire web page. The final rng.Delete assertion deletes the chosen web page. A remaining Set assertion destroys the rng object.

There’s a minimal of error-handling. Ought to an unhandled error come up, the MsgBox() assertion will show that error quantity and outline. For example, if the consumer enters something apart from a quantity, the MsgBox() operate will show the message 13: Kind Mismatch.

Code A

Sub FindDeletePage()

'Go to particular web page and delete it.

'Could be undone with Ctrl + z.

Dim rng As Vary

Dim pge As Integer

On Error GoTo Errhandler:

pge = InputBox("Please enter variety of web page you wish to delete.", "Delete web page")

Set rng = ActiveDocument.Vary(0, 0)

Set rng = rng.GoTo(What:=wdGoToPage, Title:=pge)

Set rng = rng.GoTo(What:=wdGoToBookmark, Title:="web page")

rng.Delete

Set rng = Nothing

Exit Sub

Errhandler:

MsgBox Err.Quantity & ": " & Err.Description

Set rng = Nothing

Finish Sub

Now let’s enter the VBA process.

How you can enter the VBA process in Phrase

Should-read Home windows protection

If you happen to’re acquainted with VBA, you may in all probability skip this part and transfer proper on to the following part, the place we’ll run the process to see the way it works.

To enter the process, press Alt + F11 to open the Visible Primary Editor. Within the Undertaking Explorer to the left, choose ThisDocument. If you happen to enter the code manually, don’t paste from this net web page. As an alternative, copy the code right into a textual content editor after which paste that code into the ThisDocument module. Doing so will take away any phantom net characters which may in any other case trigger errors.

If you happen to’re utilizing a ribbon model, you’ll want to save the workbook as a macro-enabled file. If you happen to’re working within the menu model, you may skip this step. Now, let’s run the process and see the way it works.

How you can run the process

We’ll use the process to delete a web page within the five-page doc proven in Determine A. There are two note-worthy issues to say earlier than we accomplish that:

  1. This process gained’t delete the final web page. It’s going to delete the content material, however it gained’t delete the web page.
  2. In case your web page numbering scheme doesn’t replicate the precise web page quantity — suppose you begin web page quantity on web page 2 in order that the web page quantity within the header shows 1 relatively than 2 — VBA will account for this and delete the web page displaying web page 2, which might be web page 3 by precise depend.

Determine A

We’ll delete one of many pages on this doc.

Every web page shows a distinct font coloration and a web page quantity within the header. That’s so you may visually discern that the process deletes a web page. Observe that web page 2, the web page will delete, is inexperienced.

Earlier than operating the process, click on inside any web page apart from 2. The macro will delete the present web page with no downside, however I would like you to see that it’ll additionally delete a web page apart from the present web page — that’s the main target of this process.

Click on the Developer tab after which click on Macros within the Code group. Within the ensuing dialog field, choose FindDeletePage(), as proven in Determine B, and click on Run.

Determine B

Select the process FindDeletePage().

When the code shows the InputBox(), enter 2, as proven in Determine C and click on OK.

Determine C

Enter 2 to delete the web page 2.

Determine D

The process deleted web page 2.

As you may see in Determine D, the inexperienced web page, web page 2, is gone and web page three (purple) has moved as much as web page 2.

Almost certainly, you gained’t wish to work by all these steps to run this macro. I like to recommend that you just add it to the Fast Entry Toolbar or a customized group. If you happen to need assistance with that, learn How you can add Workplace macros to the QAT toolbar for fast entry.



Source link

Related

Tags: DeletePageselectsingleVBAWord
ShareTweetSend

Related Posts

Technology

Elden Ring’s story no longer makes you invade other players’ games

August 9, 2022
Technology

To optimize for growth, study your down-funnel metrics – TechCrunch

August 9, 2022
Technology

Micron plans to spend $40B by 2030 to expand US chip manufacturing capacity, aided by government grants and credits, and expects to begin production after 2025 (Prarthana Prakash/Bloomberg)

August 9, 2022
Technology

‘Ted Lasso’ stars thought no one would watch Apple TV+

August 9, 2022
Technology

How to upgrade to Linux Mint 21 using the Upgrade Tool

August 9, 2022
Technology

Why this fall will bring the biggest devices Apple has ever made

August 9, 2022
Load More
Next Post

Baptist Health Hits Construction Milestone On Ambulatory Care Center In Kentucky

First recorded sighting of North America by a European takes place as explorer John Cabot spots land – Chicago Tribune

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn ontology for data integration and NLP

LATEST UPDATES

Chipotle to pay NYC workers $20m for violating city labour laws | Workers’ Rights News

August 9, 2022

Elden Ring’s story no longer makes you invade other players’ games

August 9, 2022

Marshawn Lynch arrested on suspicion of DUI in Las Vegas

August 9, 2022

U.S. Signs Measure Giving Approval to Sweden and Finland’s Bid to Join NATO

August 9, 2022

´Ronaldo to Atletico, why not?´ – Guti believes Real Madrid legend could make controversial LaLiga r

August 9, 2022
Load More
Now And Then News

Get the latest news and follow the coverage of breaking news, local news, national, politics, and more from the world's top trusted sources.

Categories

  • Business
  • Defense
  • Entertainment
  • Health
  • International
  • Lifestyle
  • National
  • Politics
  • Sports
  • Technology
  • Travel
  • Uncategorized

Site Map

  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact

Recent Posts

  • Chipotle to pay NYC workers $20m for violating city labour laws | Workers’ Rights News
  • Elden Ring’s story no longer makes you invade other players’ games
  • Marshawn Lynch arrested on suspicion of DUI in Las Vegas

Copyright © 2021 Now And Then News .
Now And Then News funded by Vnome LLC, participates in the Amazon Services LLC Associates Program,
which is an affiliate advertising program designed to provide a means for websites to earn advertising fees by advertising and linking to amazon.com.

No Result
View All Result
  • Home
  • National
  • International
  • Politics
  • Defense
  • Business
  • Health
  • Sports
  • Technology
  • Entertainment
  • Lifestyle
  • Travel

Copyright © 2021 Now And Then News .
Now And Then News funded by Vnome LLC, participates in the Amazon Services LLC Associates Program,
which is an affiliate advertising program designed to provide a means for websites to earn advertising fees by advertising and linking to amazon.com.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In