Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2021, 11:53 AM
Stephen Ray Stephen Ray is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2016
Novice
Would Like to test if Full Name is NOT Present in document
 
Join Date: Sep 2018
Location: Kansas
Posts: 29
Stephen Ray is on a distinguished road
Default Would Like to test if Full Name is NOT Present in document

I would like to determine if there is NO Full Name in a document.

Please find one attachment, a few lines from the document. I run a Word VBA Macro on this many times every day.
In the attachment you may see two, (2) different ways I get the document.
Some with a Full Name, others with none.


I would like to determine if there is NO Full Name on the document.
Something like this:
If the Full Name is there
Do Something
Else
Do SomethingElse

The funny formatting symbols and strange formatting is giving me trouble. I don't know if this columns or a table or what.
Thanks in advance for helping me with this.
Attachments
Attached Files
File Type: docx DocX.docx (22.4 KB, 6 views)
Reply With Quote
  #2  
Old 11-23-2021, 02:36 PM
Guessed's Avatar
Guessed Guessed is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,753
Guessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud of
Default

There is always a fullname but if a file is new and has never been saved then there won't be a path.
Code:
Sub SavedNotSaved()
  If ActiveDocument.Path = "" Then    'file is new and not saved with filename
    Debug.Print "New unsaved doc"
  Else
    Debug.Print "It's been saved"
  End If
End Sub
In an unsaved document, fullname returns the name in the banner eg Document1
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-23-2021, 04:48 PM
Stephen Ray Stephen Ray is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2016
Novice
Would Like to test if Full Name is NOT Present in document
 
Join Date: Sep 2018
Location: Kansas
Posts: 29
Stephen Ray is on a distinguished road
Default

Guessed, Thank you for your reply. But this document is not saved anywhere, it comes from an application that I work with; the original input document that is not in Word Format. I copy the whole enchilada - original information by highlighting it and Cntrl + C.
With all the information in the clipboard, I turn to a second monitor where Microsoft Word is waiting. I immediately start a macro which pastes all the information and arranges it in a Word document. The Macro saves lots of time and effort by re-arranging it all.

But I need to be able to test when the full name is present or not.

I thought I would highlight and SELECT the area where the Full Name is supposed to be. (The VBA MACRO can easily highlight and SELECT the area where the Full Name is supposed to be). If I could test the SELECTION for Alpha or Alphanumeric that would work.

But from my searching there is only a ISNUMERIC. There is no ISALPHANUMERIC test.
Reply With Quote
  #4  
Old 11-23-2021, 05:50 PM
Guessed's Avatar
Guessed Guessed is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,753
Guessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud ofGuessed has much to be proud of
Default

It appears that you mean Full Name to be content inside a table next to a cell that is labelled "Employee's Full name who is being Deleted: :" - Is that correct?

The document you posted contains two tables with that label. The first table has an empty cell beside it, the second table contains "John Jones" in that cell. It is not apparent whether that means the file does or doesn't contain a full name. Nor is it apparent whether there will be more tables in the document with other structures that also need to be examined by a macro.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 11-24-2021, 08:00 AM
Stephen Ray Stephen Ray is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2016
Novice
Would Like to test if Full Name is NOT Present in document
 
Join Date: Sep 2018
Location: Kansas
Posts: 29
Stephen Ray is on a distinguished road
Default

Guessed, thank you for your reply.
I have attached another document, the whole document.
This is just like my macro pastes in the Word document, before it starts rearranging it.

So this is a table, you say. I know nothing about tables in Word. But I used to write programs in COBOL with tables, so I can learn it fast.

Is there any way we could write code to say something like. "Look at the cell next to the cell that contains: Employee's Full name who is being Deleted: : ??

Or does the code have to say something like: Look at cell X1 ??
Attached Files
File Type: docx WholeDocument.docx (33.4 KB, 6 views)
Reply With Quote
  #6  
Old 11-25-2021, 04:49 PM
Stephen Ray Stephen Ray is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2016
Novice
Would Like to test if Full Name is NOT Present in document
 
Join Date: Sep 2018
Location: Kansas
Posts: 29
Stephen Ray is on a distinguished road
Default

Guessed, Yes, Full Name is content inside a table next to a cell that is labelled "Employee's Full name who is being Deleted: :"
Reply With Quote
  #7  
Old 11-26-2021, 02:41 AM
gmayor's Avatar
gmayor gmayor is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2019
Expert
 
Join Date: Aug 2014
Posts: 3,633
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

The following should work. There is however nothing in that cell in your sample.

Code:
Function GetDeleted(oDoc As Document) As String
Dim oTable As Table
Dim oCell As Range
Dim i As Long
Dim sName As String
    Set oTable = oDoc.Tables(1)
    For i = 1 To oTable.Rows.Count
        If InStr(1, oTable.Cell(i, 1).Range.Text, "Deleted:") > 0 Then
            Set oCell = oTable.Cell(i, 2).Range
            oCell.End = oCell.End - 1
            sName = oCell.Text
            Exit For
        End If
    Next i
    GetDeleted = sName
    Set oTable = Nothing
    Set oCell = Nothing
End Function

Sub Test()
Dim sText As String
    sText = GetDeleted(ActiveDocument)
    If sText = "" Then
        MsgBox "There is no name in the cell", vbCritical
    Else
        MsgBox sText, vbInformation
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #8  
Old 11-26-2021, 08:50 AM
Stephen Ray Stephen Ray is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2016
Novice
Would Like to test if Full Name is NOT Present in document
 
Join Date: Sep 2018
Location: Kansas
Posts: 29
Stephen Ray is on a distinguished road
Default

GMayor, Thank you for your reply. Yes, in that sample document there is nothing in that cell. In the documents I must work with, sometimes a name is there and sometimes there is not.
I would like to test only the one cell, just to the right side of "Employee's Full name who is being Deleted: :" (I think I see how you do this in the code.)
So the whole idea here, is to test when there is a name there and when there is nothing there.
Thank you for the code, I will try to understand your code and test it to see how it works.
I will get back to you in a few days, The family thinks I should take a few days off for Thanksgiving.
Reply With Quote
  #9  
Old 11-27-2021, 08:54 AM
Stephen Ray Stephen Ray is offline Would Like to test if Full Name is NOT Present in document Windows 10 Would Like to test if Full Name is NOT Present in document Office 2016
Novice
Would Like to test if Full Name is NOT Present in document
 
Join Date: Sep 2018
Location: Kansas
Posts: 29
Stephen Ray is on a distinguished road
Default

GMayor,
It works. Omigosh! I can understand what it is doing, but I never could have written it.
It steps through the entire table looking for "Deleted:"
But it only loads sName when there is a match.
I did not know VBA could do a FOR - I have been using FOR in PowerShell, so I recognize it. It is just a loop.
This saves a lot of time. And I will be able to use this in other ways.
I will experiment because I want to test for the condition when there are only spaces in that cell too. They might put spaces in the cell too.
Many Thanks.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Would Like to test if Full Name is NOT Present in document Creating a full page document from a ragged one. Balliol Word 5 04-28-2021 07:46 PM
Full screen view to specific document matapagi2019 Word VBA 0 03-17-2019 10:42 AM
Detecting that previous character doesn't exist (i.e., present character is first in document) Robert K S Word VBA 15 08-01-2016 09:33 AM
Would Like to test if Full Name is NOT Present in document Master document missing images present in Subdocument Dart82 Word 2 05-05-2014 08:35 AM
how to add test in word document tekle Word 2 05-24-2010 01:26 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:41 AM.


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