Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #13  
Old 03-31-2021, 03:51 PM
Guessed's Avatar
Guessed Guessed is offline Macro doesnt work inside textbox Windows 10 Macro doesnt work inside textbox 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

I don't understand why there needs to be multiple steps so my solution may not be what you wanted. I would approach this by making use of checkbox content controls and having a macro check the user logon name to determine how to expand the user details.

This approach then just expects the user to just check a box and then move their cursor in order to see their details replace the checkbox immediately. To me this is much simpler in terms of usability.

I've attached a demo document showing how this is set up. The code that is being used in the file is
Code:
Private Sub Document_ContentControlOnExit(ByVal aCC As ContentControl, Cancel As Boolean)
  Dim sUser As String, sID As String
  sID = Environ$("UserName")
  If aCC.Type = wdContentControlCheckBox Then
    If aCC.Checked Then
      sUser = ExpandUser(sID)
      If sUser <> "" Then
        aCC.Type = wdContentControlText
        aCC.MultiLine = True
        aCC.Range.Text = sUser
      End If
    End If
  End If
End Sub

Function ExpandUser(sID As String) As String
  Select Case sID
    Case "winki", "winkidelegate"
      ExpandUser = "V. d. strokovnega direktorja" & vbCr & "Valentina Winkler Skaza, dr. med., spec. psih."
    Case "mario123"
      ExpandUser = "Pomocnik direktorja za podrocje zdravstvene nege " & vbCr & "Mario Dremšak, mag. manag., dipl. zn."
    Case Else
      Application.StatusBar = "Not a recognised user: " & sID
  End Select
End Function

Sub ResetCheckBoxes()
  Dim aCC As ContentControl
  For Each aCC In ActiveDocument.SelectContentControlsByTag("Signed")
    aCC.Type = wdContentControlCheckBox
    aCC.Checked = False
  Next aCC
End Sub
Attached Files
File Type: docm Demo.docm (32.2 KB, 14 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro doesnt work inside textbox DocumentBeforePrint doesnt work Gerrit Word VBA 6 02-20-2021 08:53 AM
Macro doesnt work inside textbox Code doesnt work properly ksigcajun Word VBA 6 04-06-2015 07:41 AM
Safe Senders Doesnt work Anil Kaul Outlook 0 11-16-2012 01:28 PM
Macro doesnt work inside textbox Command Button doesnt work on network rmw85 Word VBA 1 04-25-2012 01:02 PM
Macro doesnt work inside textbox My Product code doesnt work!!!! PLEASE HELP dukquaknoobhack Office 1 01-05-2012 03:43 PM

Other Forums: Access Forums

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