Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-09-2023, 03:35 PM
Guessed's Avatar
Guessed Guessed is offline VBA detecting style used Windows 10 VBA detecting style used Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
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

It is pretty much the same way. At its simplest you could follow this pattern


Code:
Sub GetStyled()
  Dim sSty As String
  sSty = Selection.Style
  If sSty = "Normal" Then
    Selection.Style = "Heading 2"
  Else
    Selection.Style = "Heading 3"
  End If
End Sub
If your selection includes multiple styles (eg more than one paragraph selected or character style + paragraph style) then you may need to complicate the code to get the right results.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA detecting style used Need help detecting the reason for a strange behavior of a UDF soroush.kalantari Excel Programming 9 08-12-2022 07:05 PM
Detecting Write Access Password azizrasul PowerPoint 0 04-05-2021 10:56 AM
Detecting an active instance of Excel from Word VBA Sorcerer13 Word VBA 17 06-02-2014 02:48 AM
Detecting last cell within a block Funk Excel 12 10-01-2013 04:26 AM
VBA detecting style used detecting triggers yisuz PowerPoint 1 05-15-2012 09:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft