Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-24-2022, 04:12 PM
Guessed's Avatar
Guessed Guessed is offline access active cell in word vba Windows 10 access active cell in word vba Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

There are a couple of tricks involved here. First is to avoid an error if the selection doesn't include any table elements. Second is to avoid having the end of cell marker as part of your string.
Code:
Sub Macro1()
  Dim str As String, aCell As Cell
  If Selection.Tables.Count > 0 Then
    str = Selection.Cells(1).Range.Text
    str = Left(str, Len(str) - 2)
  End If
  MsgBox "Text in first selected cell: " & str
End Sub

__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Move active cell down Marcia Excel Programming 2 06-22-2022 04:10 PM
access active cell in word vba Change active cell after running macro in active cell via selection change Peterson Excel Programming 3 03-07-2021 12:19 PM
Cell equal value new value of active cell which is a drop down hassanmoukadem Excel Programming 1 04-13-2020 07:54 PM
Active cell not the one I select with curser. hayesfam3 Excel 0 08-15-2019 05:14 AM
access active cell in word vba Clear all cell colors within a range starting at cell A8 and change row of active cell to yellow FUGMAN Excel Programming 7 02-05-2017 08:37 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:34 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