Excel VBA: Replace/convert date fields in header and footer to sample text

Diskutiere und helfe bei Excel VBA: Replace/convert date fields in header and footer to sample text im Bereich Microsoft Office im Windows Info bei einer Lösung; I need an excel macro to replace all date fields in the header and footer to a sample text like "here was a date" and unlink all other fields. I have a... Dieses Thema im Forum "Microsoft Office" wurde erstellt von Robin Huber, 30. Mai 2022.

  1. Excel VBA: Replace/convert date fields in header and footer to sample text


    I need an excel macro to replace all date fields in the header and footer to a sample text like "here was a date" and unlink all other fields. I have a solution already for Word but I don't know how to do it in Excel. This word macro will unlink all fields and search for date and time fields and replace it with a sample text.Here is my macro for Word:Sub AutoOpen Dim oField As Field, bErrMark As Boolean, strPrompt As String, bFieldCodeHidden As Boolean Dim oStory As Range Const strREPLACETEXT = "{TIME\@dd.MMMM.yyyy}" ' Text für die Ersetzung On Error GoTo OOPS
     
  2. Robin Huber Win User

    Unlink Fields in Excel and PowerPoint

    Hello

    Thanks for the answers. But that's not what I'm looking for.

    I search for a solution to "unlink" the fields in header and footer. For example a date field, which updates when I print or open the file.

    In word I can do this with a macro, but in excel and powerpoint that solution didn't worked.
  3. CharlesKenyon IA Win User

    WORD MACRO: Search for date fields and replace result

  4. Robin Huber Win User

    WORD MACRO: Search for date fields and replace result

    Try this:

    Sub DateFieldsReplace()
    ' Replace any date fields in active document
    ' Charles Kenyon 2020-09-09

    ' https://answers.microsoft.com/de-de/msoffice/forum/all/word-macro-search-for-date-fields-and-replace/ad578c92-e1ce-4258-903f-552dfae2a843
    ' =====================================================
    ' DECLARE VARIABLES AND CONSTANTS
    Dim oField As Field, bErrMark As Boolean, strPrompt As String, bFieldCodeHidden As Boolean
    Dim oStory As Range
    Const strREPLACETEXT = "Hello" ' Change to suit
    '
    ' =====================================================
    ' TURN OFF SCREEN UPDATING
    ' Application.ScreenUpdating = False
    On Error GoTo OOPS
    Let bFieldCodeHidden = ActiveWindow.View.ShowFieldCodes ' get current setting for field code display
    Let ActiveWindow.View.ShowFieldCodes = True
    '
    ' =====================================================
    ' FIND AND REPLACE DATE FIELDS
    For Each oStory In ActiveDocument.StoryRanges
    With oStory.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^d Date"
    .Replacement.Text = strREPLACETEXT
    .Execute Replace:=wdReplaceAll
    .Text = "^d Time"
    .Execute Replace:=wdReplaceAll
    End With
    Next oStory
    '
    Let strPrompt = "All Date fields replaced with " & strREPLACETEXT
    GoTo ResumeMacro
    ' =====================================================
    ' ERROR HANDLER
    OOPS:
    Let strPrompt = "Sorry. There was a problem with the macro DateFieldsReplace."
    '
    ResumeMacro:
    '
    ' =====================================================
    ' RETURN SCREEN UPDATING AND FINISH
    With ActiveDocument.Range.Find
    .ClearFormatting
    .Text = ""
    .Replacement.ClearFormatting
    .Replacement.Text = ""
    End With
    Application.ScreenUpdating = True
    Application.ScreenRefresh
    Set oField = Nothing

    Set oStory = Nothing
    Let ActiveWindow.View.ShowFieldCodes = bFieldCodeHidden
    On Error GoTo -1

    MsgBox strPrompt
    '
    End Sub
    Here is a temporary link to the document with this code:

    https://www.dropbox.com/s/ro15269h5zy6mnk/delet...
    Hi

    This works fine thanks you!

    What does it need to execute this VBA for a folder (with subfolders) to manipulate the word files in this folders?

    Thank you!
  5. Robin Huber Win User

    Unlink Fields in Excel and PowerPoint

    The field don't update anymore and is simply text. I need to convert multiple PDFs and they'd have the original things of the document not the updated fields.

    The Code in Word: ActiveDocument.Fields.Unlink
  6. CharlesKenyon IA Win User

    WORD MACRO: Search for date fields and replace result

    Try this:

    Sub DateFieldsReplace()
    ' Replace any date fields in active document
    ' Charles Kenyon 2020-09-09

    ' https://answers.microsoft.com/de-de/msoffice/forum/all/word-macro-search-for-date-fields-and-replace/ad578c92-e1ce-4258-903f-552dfae2a843
    ' =====================================================
    ' DECLARE VARIABLES AND CONSTANTS
    Dim oField As Field, bErrMark As Boolean, strPrompt As String, bFieldCodeHidden As Boolean
    Dim oStory As Range
    Const strREPLACETEXT = "Hello" ' Change to suit
    '
    ' =====================================================
    ' TURN OFF SCREEN UPDATING
    ' Application.ScreenUpdating = False
    On Error GoTo OOPS
    Let bFieldCodeHidden = ActiveWindow.View.ShowFieldCodes ' get current setting for field code display
    Let ActiveWindow.View.ShowFieldCodes = True
    '
    ' =====================================================
    ' FIND AND REPLACE DATE FIELDS
    For Each oStory In ActiveDocument.StoryRanges
    With oStory.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^d Date"
    .Replacement.Text = strREPLACETEXT
    .Execute Replace:=wdReplaceAll
    .Text = "^d Time"
    .Execute Replace:=wdReplaceAll
    End With
    Next oStory
    '
    Let strPrompt = "All Date fields replaced with " & strREPLACETEXT
    GoTo ResumeMacro
    ' =====================================================
    ' ERROR HANDLER
    OOPS:
    Let strPrompt = "Sorry. There was a problem with the macro DateFieldsReplace."
    '
    ResumeMacro:
    '
    ' =====================================================
    ' RETURN SCREEN UPDATING AND FINISH
    With ActiveDocument.Range.Find
    .ClearFormatting
    .Text = ""
    .Replacement.ClearFormatting
    .Replacement.Text = ""
    End With
    Application.ScreenUpdating = True
    Application.ScreenRefresh
    Set oField = Nothing

    Set oStory = Nothing
    Let ActiveWindow.View.ShowFieldCodes = bFieldCodeHidden
    On Error GoTo -1

    MsgBox strPrompt
    '
    End Sub
    Here is a temporary link to the document with this code:

    https://www.dropbox.com/s/ro15269h5zy6mnk/delet...
  7. User Advert


    Hi,

    willkommen im Windows Forum!
Thema:

Excel VBA: Replace/convert date fields in header and footer to sample text - Microsoft Office

Die Seite wird geladen...

Excel VBA: Replace/convert date fields in header and footer to sample text - Similar Threads - Excel VBA Replace

Forum Datum

WORD MACRO: Search for date fields and replace result

WORD MACRO: Search for date fields and replace result: Hi I'm working on a solution to search date fields in Word and replace the result. Replacing the result should be easy but how can I search for date fields?
Microsoft Office 9. September 2020

WORD VBA: Search for datefields and convert to text

WORD VBA: Search for datefields and convert to text: Hello Does anybody know how I can search for datefields in Word VBA? Convert to text should be easy with the unlin method. Thanks for your help!
Microsoft Office 8. September 2020

Microsoft Word - Replace Header/ Footer

Microsoft Word - Replace Header/ Footer: Is it possible to replace the header/footer in multiple documents without changing the document properties?
Microsoft Office 7. Juli 2020

Excel - Unlink all header and footer fields by opening

Excel - Unlink all header and footer fields by opening: Hello I want to unlink the fields in the header and footer just like this example: https://stackoverflow.com/questions/42829402/vba-excel-unlink-headers-footers-in-word This example shows the...
Microsoft Office 23. Juni 2020

Unlink Fields in Excel and PowerPoint

Unlink Fields in Excel and PowerPoint: Hello How can I convert the fields dates, path... in powerpoint and excel to text? I know there's a chance to do this in word and it works fine. But how can I do it in powerpoint or excel? The...
Microsoft Office 16. Juni 2020

Excel VBA Text in Form anzeigen

Excel VBA Text in Form anzeigen: Hallo, NG, ich habe eine Anforderung, die Zellwerte in den nebenstehenden 2 Spalten graphisch darzustellen, mein Vorgänger hat das mit einem Diagramm gemacht, was eher schlecht funktioniert hat,...
Microsoft Office 17. März 2017

MS Word footer and header

MS Word footer and header: I have a problem that frustrates me, SOOO Bad. I have 5 pages and 2 of them are in Horizontal format the other 3 are in Vertical format. Now the problem is the footer und Header! I can not fix a...
Microsoft Office 10. November 2016
Excel VBA: Replace/convert date fields in header and footer to sample text solved
  1. Diese Seite verwendet Cookies, um Inhalte zu personalisieren, diese deiner Erfahrung anzupassen und dich nach der Registrierung angemeldet zu halten.
    Auf dieser Website werden Cookies für die Zugriffsanalyse und Anzeigenmessung verwendet.
    Wenn du dich weiterhin auf dieser Seite aufhältst, akzeptierst du unseren Einsatz von Cookies.