View Single Post
 
Old 03-28-2022, 07:37 AM
skarden skarden is offline Windows Vista Office 2010 64bit
Novice
 
Join Date: Dec 2011
Location: Orlando, FL
Posts: 27
skarden is on a distinguished road
Default

BTW, I found that when you undelete a Date (calendar) control it doesn't come back as a date CC. It also doesn't remember the date format or storage formate. So I had to create variables that save my CC's type, date format (e.g. MM/dd/YYYY) and storage formate (for this later one, I often set it to just Date vs Date and Time if it is just a date)

So at the top in my Dim section I added:

Dim sDate_Format As String 'In case we have a Date control we will have to reset its format after it is undeleted
Dim sDate_Storage As String
Dim sType As String 'Need this because we have to reset the type to Date after it is undeleted if it was a date CC

And then when I found it I added:
sType = CC.Type
If sType = wdContentControlDate Then
sDate_Format = CC.DateDisplayFormat
sDate_Storage = CC.DateStorageFormat
End If

Finally after I did the undelete I added:
If sType = wdContentControlDate Then 'If you check sType it will be 6 which is the Date type.
ActiveDocument.ContentControls(sCC_ID).Type = wdContentControlDate
ActiveDocument.ContentControls(sCC_ID).DateDisplay Format = sDate_Format 'We also have to rest date display, e.g. MM/dd/YYY
ActiveDocument.ContentControls(sCC_ID).DateStorage Format = sDate_Storage 'We also have to rest date storage format, e.g. date only
End If

I also wanted to note that I needed to put a DoEvents after the Delete as I found that date controls were not always being undeleted (and as I mentioned, it wasn't being undeleted as a Date control). It may be that was because it wasn't being undeleted as a Date control it had to take extra time to decide what to restore it as, and because on top of that my CC was nested 3 deep, or just because. In any event. Adding the DoEvents there seems to have solved that.

I also found that it was having problems with CC.Delete so when I found my CC I saved its ID to sCC_ID and then replaced CC.Delete with:
ActiveDocument.ContentControls(sCC_ID).Delete
Reply With Quote