דילוג לתוכן
  • חוקי הפורום
  • לא נפתר
  • משתמשים
  • חיפוש גוגל בפורום
  • צור קשר
עיצובים
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • ברירת מחדל (ללא עיצוב (ברירת מחדל))
  • ללא עיצוב (ברירת מחדל)
כיווץ
לוגו מותג
  1. דף הבית
  2. תוכנות
  3. יישומי אופיס
  4. וורד
  5. עזרה הדדית - וורד
  6. שיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....

שיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....

מתוזמן נעוץ נעול הועבר עזרה הדדית - וורד
50 פוסטים 6 כותבים 1.7k צפיות 6 עוקבים
  • מהישן לחדש
  • מהחדש לישן
  • הכי הרבה הצבעות
תגובה
  • תגובה כנושא
התחברו כדי לפרסם תגובה
נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
  • P pcinfogmach

    קוד עיצוב פיסקה כנהוג בספרי קודש - מילה ראשונה, חלון, ומירכוז שורה אחרונה:
    קרדיט ל- @NykUser @מאקרו ו-@pcinfogmach

    מצו"ב שני שיטות:

    בשיטה הראשונה - עובד יותר חלק ומקצועי אבל כדי לערוך שינויים צריך להריץ שוב את המאקרו כדי לתקן את העיצוב.

    בשיטה השניה - אפשר לערוך שינויים ללא בעיות.
    יש בה שני חסרונות אומנם:
    1.שהמירכוז שורה אחרונה הופך את הגדרות הטאבים שבמסמך ל-'0 '.
    2.שבעיצוב חלון נוצר סטייה בגובה השורה בין המילה הראשונה לשורה הראשונה (אפשר לפתור זאת על ידי הגדרת רווח פיסקה - כולל החלון - כמדוייק באפשרויות פיסקה).


    שיטה ראשונה:
    חלון.bas
    שורה_אחרונה.bas

    Sub עיצוב_מילה_ראשונה_לפי_סגנון()
    
       Dim myDialog As Dialog, para As Paragraph, rng As Range, styl As String
       
        styl = ActiveDocument.Styles(wdStyleStrong).NameLocal
        Set rng = Selection.Range
        Set myDialog = Dialogs(wdDialogFormatStyle)
        
        
        Selection.MoveUp Unit:=wdParagraph, Count:=1
        
        With myDialog
            .Name = styl
            .Display
            End With
                  
       For Each para In rng.Paragraphs
        With para.Range
        .End = .Start
        .MoveEndUntil " ", wdForward
        .Select
        End With
        myDialog.Execute
        Next para
        
    End Sub
    
    Sub עיצוב_מילה_ראשונה_ללא_סגנון()
    
       Dim myDialog As Dialog, para As Paragraph, rng As Range
       
        Set rng = Selection.Range
        Set myDialog = Dialogs(wdDialogFormatFont)
        
        myDialog.Display
               
       For Each para In rng.Paragraphs
        With para.Range
        .End = .Start
        .MoveEndUntil " ", wdForward
        .Select
        End With
        myDialog.Execute
        Next para
        
    End Sub
    
    Sub הסר_עיצוב_מילה_ראשונה()
    
       Dim para As Paragraph, rng, mrng As Range
               
       Set rng = Selection.Range
       
       For Each para In rng.Paragraphs
         
        With para.Range
            .Collapse: .MoveUntil cset:=" ": .MoveEnd: .Collapse Direction:=wdCollapseEnd
            .move Unit:=wdCharacter, Count:=1
            .Select
        End With
          
        Selection.CopyFormat
        Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
        Selection.PasteFormat
        Application.ScreenRefresh
        Next para
        
    End Sub
    

    שיטה שניה:

    Option Explicit
    '
    '
    '
    'עיצוב חלון על עיקרון מסגרת
    ' עיצוב מילה ראשונה על עיקרון של החלת סגנון
    ' עיצוב שורה אחרונה על עיקרון של שלמה מימות ממתמחים טופ
    '
    
    
    Private Sub עיצוב_מהיר_כל_העיצובים()
    
    'קביעת הטווח
    Dim slctd As Range
    Set slctd = Selection.Range
    slctd.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End
    
    slctd.Select
    
    'הוסף סימנים ומרכז שורה אחרונה
    Call part1(slctd)
    
    'הוסף מעבר שורה עם סימנים לפני פיסקה ראשונה
        slctd.InsertBefore "$$$$$$$$$" & Chr(13)
    
    'הכנות בשביל עיצוב מילה ראשונה או חלון
    Call part2(slctd)
    'יצירת הסגנונות אם צריך
    Call part3A
    Call part3B
    'החלת סגנון חלון
    Call part4A
    'החלת סגנון בלי חלון עבור פסקאות עם פחות מארבע שורות
    Call part4c
    'ניקוי שאריות
    Call part5
    'msgbox תיקון הסטייה
    
    End Sub
    Private Sub עיצוב_מהיר_שורה_אחרונה_ומילה_ראשונה_בלי_חלון()
    
    'קביעת הטווח
    Dim slctd As Range
    Set slctd = Selection.Range
    slctd.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End
    
    'הוסף סימנים ומרכז שורה אחרונה
    Call part1(slctd)
    
    'הוסף מעבר שורה עם סימנים לפני פיסקה ראשונה
        slctd.InsertBefore "$$$$$$$$$" & Chr(13)
    
    'הכנות בשביל עיצוב מילה ראשונה או חלון
    Call part2(slctd)
    
    'יצירת הסגנונות אם צריך
    Call part3B
    
    'החלת סגנון מילה ראשונה
    Call part4B
    
    'החלת סגנון בלי חלון עבור פסקאות עם פחות מארבע שורות
    Call part4c
    
    'ניקוי שאריות
    Call part5
    
    End Sub
    
    Private Sub עיצוב_מהיר_הסר_את_כל_העיצובים()
    
    Call part6
    Call הסר_מרכוז_שורה_אחרונה
    
    End Sub
    
    Private Sub עיצוב_מהיר_מילה_ראשונה_עם_חלון()
    
    'קביעת הטווח
    Dim slctd As Range
    Set slctd = Selection.Range
    slctd.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End
    
    'הוסף סימנים
    Call part1B(slctd)
    
    'הוסף מעבר שורה עם סימנים לפני פיסקה ראשונה
        slctd.InsertBefore "$$$$$$$$$" & Chr(13)
    
    
    'הכנות בשביל עיצוב מילה ראשונה או חלון
    Call part2(slctd)
    'יצירת הסגנונות אם צריך
    Call part3A
    Call part3B
    'החלת סגנון חלון
    Call part4A
    'החלת סגנון בלי חלון עבור פסקאות עם פחות מארבע שורות
    Call part4c
    'ניקוי שאריות
    Call part5
    
    
    
    
    End Sub
    Private Sub עיצוב_מהיר_מילה_ראשונה_בלי_חלון()
    
    'קביעת הטווח
    Dim slctd As Range
    Set slctd = Selection.Range
    slctd.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End
    
    'הוסף סימנים
    Call part1B(slctd)
    
    'הוסף מעבר שורה עם סימנים לפני פיסקה ראשונה
        slctd.InsertBefore "$$$$$$$$$" & Chr(13)
    
    'הכנות בשביל עיצוב מילה ראשונה או חלון
    Call part2(slctd)
    
    'יצירת הסגנונות אם צריך
    Call part3B
    
    'החלת סגנון מילה ראשונה
    Call part4B
    
    'החלת סגנון בלי חלון עבור פסקאות עם פחות מארבע שורות
    Call part4c
    
    'ניקוי שאריות
    Call part5
    
    End Sub
    
    Private Sub עיצוב_מהיר_מרכוז_שורה_אחרונה()
    
    'קביעת הטווח
    Dim slctd As Range
    Set slctd = Selection.Range
    slctd.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End
    
    'הוסף סימנים ומרכז שורה אחרונה
    Call part1(slctd)
    
    Call part5
    End Sub
    Private Sub הסר_מילה_ראשונה_וחלון()
    
    Call part6
    
    End Sub
    Private Sub הסר_מרכוז_שורה_אחרונה()
    
    'קביעת הטווח
    Dim slctd As Range
    Set slctd = Selection.Range
    slctd.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End
    
    'הוסף סימנים בפיסקאות שנבחרו
    slctd.Find.Execute _
    FindText:="(*)(^t)(^13)", _
    ReplaceWith:="\1+++++++\3", _
    Forward:=True, Wrap:=wdFindStop, MatchWildcards:=True, _
    Replace:=wdReplaceAll
    
    'חפש והחלף לפי סימנים
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
        
        With Selection.Find.Replacement.ParagraphFormat
            .SpaceBeforeAuto = False
            .SpaceAfterAuto = False
            .Alignment = wdAlignParagraphJustify
        End With
        With Selection.Find
            .Text = "(*)(+++++++)(^13)"
            .Replacement.Text = "\1\3"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        
    End Sub
    
    Sub part1(slctd As Range) ' Do something with slctd here
    '
    'מרכוז שורה אחרונה
    '
    
        'שינוי הטאבים ל- 0
        Selection.ParagraphFormat.TabStops.ClearAll
        ActiveDocument.DefaultTabStop = CentimetersToPoints(0)
        
    'החלת עיצוב שורה אחרונה
        Dim p As Paragraph
        For Each p In slctd.Paragraphs
            ' Check if paragraph contains more than one line
            If Not p.Range.ComputeStatistics(wdStatisticLines) > 1 Then
                    p.Range.InsertBefore "$#$#$#"
                        GoTo nxt
                    End If
                    
                    p.Range.ParagraphFormat.Alignment = wdAlignParagraphDistribute
                            p.Range.Characters.Last.Previous = vbTab
                   
            If Not p.Range.ComputeStatistics(wdStatisticLines) > 2 _
            Or Not p.Range.ComputeStatistics(wdStatisticLines) > 3 Then
                p.Range.InsertBefore "$#$#$#"
                End If
    nxt:
                Next p
    End Sub
    Sub part1B(slctd As Range) ' Do something with slctd here
    '
    'מרכוז שורה אחרונה
    '
    
        'שינוי הטאבים ל- 0
        Selection.ParagraphFormat.TabStops.ClearAll
        ActiveDocument.DefaultTabStop = CentimetersToPoints(0)
        
    'החלת עיצוב שורה אחרונה
        Dim p As Paragraph
        For Each p In slctd.Paragraphs
            ' Check if paragraph contains more than one line
            If Not p.Range.ComputeStatistics(wdStatisticLines) > 1 _
            Or Not p.Range.ComputeStatistics(wdStatisticLines) > 2 _
            Or Not p.Range.ComputeStatistics(wdStatisticLines) > 3 Then
                    p.Range.InsertBefore "$#$#$#"
                        
    End If
                Next p
    End Sub
                
    Private Sub part2(slctd As Range)
    '
    'הכנות בשביל עיצוב מילה ראשונה או חלון
    '
    
    'להוסיף פתרון בעיות עם סימני הערות שוליים צריך
            
    'החלת סימן החרגה עבור פיסקאות מודגשות (כותרות)
    Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
    
    Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "*^13"
            .Replacement.Text = "$$$$$$$$$^&"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .Font.BoldBi = True
            .Font.Bold = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        
        Selection.Find.Execute Replace:=wdReplaceAll
        
    'סימון המילה הראושנה והפרדתו מהפיסקה שאחריו (כדי שהסגנון יחול רק עליו ולא על כל הפיסקה
    'אין אפשרות שיחול רק עליו בלי זה כי צריך להחיל עליו מסגרת
    'אין בעיה במה שהואנפרד כי המסגרת מוגדרת לקבץ אותו יחד עם הפיסקה שאחריו
        
        slctd.Find.Execute FindText:="(^13)([!$]@ )", ReplaceWith:="\1^+^+^+^+\2^+^+^+^+^p", Forward:=True, Wrap:=wdFindStop, MatchWildcards:=True, Replace:=wdReplaceAll
    
    End Sub
    
    Private Sub part3A()
    Dim styl As Style
    
    '
    'יצירת סגנון מילה ראשונה עם חלון
    '
    
            'הוזזת הסמן לתחילת הטווח כדי למנוע עיצוב המילים המסומנות
            Selection.Collapse Direction:=wdCollapseStart
    
    'בדיקה אם הסגנון כבר קיים
            On Error Resume Next
            Set styl = ActiveDocument.Styles("מילת פתיח עם חלון עיצוב מהיר")
            On Error GoTo 0
    
    'הודעה למשתמש
    If Not styl Is Nothing Then Exit Sub
    Dim strt As VbMsgBoxResult
    strt = MsgBox("לפני שנחתחיל תצטרכו לבחור עיצוב נפרד עבור סגנון 'מילת פתיח עם חלון עיצוב מהיר'." & vbNewLine & "לאחר יצירת הסגנון תמיד תוכלו לשנותו על ידי לחיצה ימנית על הסגנון בסרגל הסגנונות." & vbNewLine & "כך או כך הלחצן יחיל את הסגנון המבוקש על המילה הראשונה שבכל פיסקה.", _
    vbInformation + vbOKCancel + vbMsgBoxRight + vbMsgBoxRtlReading, "יצירת והחלת סגנון 'מילה ראשונה בהערות שוליים'")
    If strt = vbCancel Then Exit Sub
    
            'בחירת העיצוב
            Selection.Font.Name = Selection.Font.Name
                With Dialogs(wdDialogFormatFont)
                    .Update
                    .Font = Selection.Font.Name
                    .FontNameBi = Selection.Font.Name
                    If .Show = False Then Exit Sub
                End With
                
                'יצירת הסגנון
                ActiveDocument.Styles.Add Name:="מילת פתיח עם חלון עיצוב מהיר", Type:=WdStyleType.wdStyleTypeParagraph
                ActiveDocument.Styles("מילת פתיח עם חלון עיצוב מהיר").Priority = 3
                ActiveDocument.Styles("מילת פתיח עם חלון עיצוב מהיר").QuickStyle = True
                
            
                'הגדרת הסגנון כסגנון עם מסגרת
                With ActiveDocument.Styles("מילת פתיח עם חלון עיצוב מהיר").ParagraphFormat
                    .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
                    .Borders(wdBorderRight).LineStyle = wdLineStyleNone
                    .Borders(wdBorderTop).LineStyle = wdLineStyleNone
                    .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
                            With .Borders
                                .DistanceFromTop = 1
                                .DistanceFromLeft = 4
                                .DistanceFromBottom = 1
                                .DistanceFromRight = 4
                                .Shadow = False
                            End With
                End With
                
                'הגדרות המסגרת
                With ActiveDocument.Styles("מילת פתיח עם חלון עיצוב מהיר").Frame
                    .TextWrap = True
                    .WidthRule = wdFrameAuto
                    .HeightRule = wdFrameAuto
                    .HorizontalPosition = wdFrameRight
                    .RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
                    .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
                    .HorizontalDistanceFromText = CentimetersToPoints(0.13)
                    .VerticalDistanceFromText = CentimetersToPoints(0)
                    .LockAnchor = False
                End With
    
    End Sub
    
    Private Sub part3B()
    Dim styl As Style
    '
    'יצירת סגנון מילה ראשונה בלי חלון
    '
    
            'הוזזת הסמן לתחילת הטווח כדי למנוע עיצוב המילים המסומנות
            Selection.Collapse Direction:=wdCollapseStart
    
    'בדיקה אם הסגנון כבר קיים
            On Error Resume Next
            Set styl = ActiveDocument.Styles("מילת פתיח בלי חלון עיצוב מהיר")
            On Error GoTo 0
        
    'הודעה למשתמש
    If Not styl Is Nothing Then Exit Sub
    Dim strt As VbMsgBoxResult
    strt = MsgBox("לפני שנחתחיל תצטרכו לבחור עיצוב נפרד עבור סגנון 'מילת פתיח בלי חלון עיצוב מהיר'." & vbNewLine & "לאחר יצירת הסגנון תמיד תוכלו לשנותו על ידי לחיצה ימנית על הסגנון בסרגל הסגנונות." & vbNewLine & "כך או כך הלחצן יחיל את הסגנון המבוקש על המילה הראשונה שבכל פיסקה.", _
    vbInformation + vbOKCancel + vbMsgBoxRight + vbMsgBoxRtlReading, "יצירת והחלת סגנון 'מילה ראשונה בהערות שוליים'")
    If strt = vbCancel Then Exit Sub
    
            'בחירת העיצוב
            Selection.Font.Name = Selection.Font.Name
                With Dialogs(wdDialogFormatFont)
                    .Update
                    .Font = Selection.Font.Name
                    .FontNameBi = Selection.Font.Name
                    If .Show = False Then Exit Sub
                End With
                
                'יצירת הסגנון
                ActiveDocument.Styles.Add Name:="מילת פתיח בלי חלון עיצוב מהיר", Type:=WdStyleType.wdStyleTypeCharacter
                ActiveDocument.Styles("מילת פתיח בלי חלון עיצוב מהיר").Priority = 3
                ActiveDocument.Styles("מילת פתיח בלי חלון עיצוב מהיר").QuickStyle = True
    
    End Sub
    
    Private Sub part4A()
    '
    'החלת סגנון מילה ראשונה כולל מסגרת
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        Application.ScreenRefresh
        Selection.Find.Replacement.Style = ActiveDocument.Styles("מילת פתיח עם חלון עיצוב מהיר")
       
        With Selection.Find
            .Text = "(^+^+^+^+)(*)(^+^+^+^+)"
            .Replacement.Text = "\2"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    
    Private Sub part4B()
    '
    'החלת סגנון מילה ראשונה בלי מסגרת
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        Application.ScreenRefresh
        Selection.Find.Replacement.Style = ActiveDocument.Styles("מילת פתיח בלי חלון עיצוב מהיר")
       
        With Selection.Find
            .Text = "(^+^+^+^+)(*)(^+^+^+^+)(^13)"
            .Replacement.Text = "\2"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    
    End Sub
    
    Private Sub part4c()
    '
    'בפסקאות עם פחות מארבע שורות החלת סגנון מילה ראשונה לא כולל מסגרת
    '
    
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        Selection.Find.Replacement.Style = ActiveDocument.Styles( _
            "מילת פתיח בלי חלון עיצוב מהיר")
        
        With Selection.Find
            .Text = "(^13)($#$#$#)(* )"
            .Replacement.Text = "\1\3"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
        
        
    Private Sub part5()
    '
    'ניקוי הסימנים
    '
    
    Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "$$$$$$$$$" & Chr(13)
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        
        Selection.Find.Execute Replace:=wdReplaceAll
        
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "$$$$$$$$$"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        
        Selection.Find.Execute Replace:=wdReplaceAll
        
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "$#$#$#"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchKashida = False
            .MatchDiacritics = False
            .MatchAlefHamza = False
            .MatchControl = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = True
        End With
        
        Selection.Find.Execute Replace:=wdReplaceAll
        
        
    End Sub
    
    Sub part6()
    
    '
    'הסרת עיצוב מילה ראשונה בפסקאות שנבחרו
    'מאת pcinfogmach
    '
    
        ' Declare variables
        Dim para As Paragraph, paraText As String, numSpaces, i As Integer, _
        spacePos, startSel, endSel As Long, paraRange, slctd As Range, _
        myFrame As Frame, myRange As Range
        
        ' Get number of spaces
        numSpaces = 1
        Set slctd = Selection.Range
        slctd.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End
             
        'תחילת הלולאה
        For Each para In slctd.Paragraphs
        
        ' Check if paragraph meets criteria
        If para.Range.Style Like "כותרת*" Then GoTo nxt
        If para.Range.Style Like "Heading*" Then GoTo nxt
        If Not para.Range.ParagraphFormat.Alignment <> wdAlignParagraphCenter Then GoTo nxt
     
                ' Get text of paragraph
                paraText = para.Range.Text
                
                ' Find position of first space
                spacePos = InStr(1, paraText, " ")
                
                ' Find position of selected space
                For i = 2 To numSpaces
                    spacePos = InStr(spacePos + 1, paraText, " ")
                    If spacePos = 0 Then Exit For
                Next i
                
                ' Select words
                If Not spacePos > 0 Then GoTo nxt
                    startSel = para.Range.Start
                    endSel = startSel + spacePos
                    Selection.SetRange Start:=startSel, End:=endSel
    
    Selection.Move Unit:=wdCharacter, Count:=1
    Selection.End = Selection.End + 1
        Selection.CopyFormat
        
    Selection.SetRange Start:=startSel, End:=endSel
    Selection.PasteFormat
        Selection.Start = Selection.Start - 3
        
        For Each myFrame In Selection.Frames
        Set myRange = myFrame.Range
        myRange.Select
        Selection.PasteFormat
        myFrame.Delete
        myRange.Collapse wdCollapseEnd
        myRange.Delete wdCharacter, 1
        Next myFrame
        
    Application.ScreenRefresh
    nxt:
        Next para
    
    '
    ''מניעת שגיאות
    Application.ScreenRefresh
    
    End Sub
    
    
    
    
    ד מנותק
    ד מנותק
    דאנציג
    כתב ב נערך לאחרונה על ידי
    #14

    @pcinfogmach
    הגדלה / הקטנה בחצי נקודה על טקסט נבחר. -רק כאשר הבחירה באותו גודל, וכאן המקום לבקש מי שיודע כיצד ניתן שהפונקציה תעבוד גם על מספר גדלים תע"ב אם ישתף את הציבור.

    Sub הגדלה_בחצי_נקודה()
        Selection.Font.SizeBi = Selection.Font.SizeBi + 0.5
    End Sub
    Sub הקטנה_בחצי_נקודה()
        Selection.Font.SizeBi = Selection.Font.SizeBi - 0.5
    End Sub
    
    
    מ תגובה 1 תגובה אחרונה
    1
    • P pcinfogmach

      אינצקלופדיה שיתופית למאקרו (VBA)

      פוסט זה נועד כדי לשתף קטעי קוד מוצלחים עבור פונקציות שונות במאקרו (VBA) עבור תוכנת מיקרוסופט וורד.
      הציבור מוזמן לשתף 🙂
      נ.ב. אינני מתכנן לענות על שאלות רק להעלות קטעי קוד שימושיים

      1. קוד לסימון המילה הראשונה בפיסקה בכל המסמך
      2. קוד להוספת צורה במיקום הנוכחי של הסמן במסמך
      3. איך לעשות פעולות נסתרות מעיני המשתמש - ולהגביר את מהירות הקוד
      4. קוד להתקנת תבנית בתוך תיקיית ההתחלה של וורד
      5. קוד ליצירת לולאה - עד מילוי תנאי מסויים
      6. קוד להוספת סגנון והסרתו
      7. לולאה שחוזרת על עצמה מספר פעמים קצוב
      8. טיפול בשגיאות
      9. אינטראקציה עם המשתמש בצורה יעילה - כן, לא, או ביטול. (יצירת תנאים לפי בחירת המשתמש).
      10. איך לשנות את תחום הטקסט המסומן

      11.קוד לפתיחת מסמך קובץ תיקייה או אתר אינטרנט
      12. קוד עיצוב פיסקה כנהוג בספרי קודש, חלון, מילה ראשונה, ומרכוז שורה אחרונה
      13. הגדלה והקטנה בחצי נקודה על טקסט נבחר
      14. כותרות צד
      15.כמה מוסכמויות בכתיבת קוד:
      16. מה עושים כאשר הטקסט בתוך userform לא מופיע
      17.חיפוש והחלפה במסמכים מרובים
      18. פתיחת מסמכים מרובים
      19. הכנסת טקסט נבחר (כגון מראה מקום) לתוך סוגריים.
      20.הערות ברצף ו - הסרת הערות ברצף
      21. הקטנת והגדלת סוגריים
      22. איך ליצור userform - מדריך
      23.הגדל רווחים בין מילים
      23.הסרת כל הרווחים בטקסט שסומן
      24. איך ליצור range נפרד עבור כל טור בהערות שוליים
      25. שינוי מרווח בין טורים רק בהערות שוליים
      26. קוד חמוד להעתקת כל המודולים מתבנית אחת לשניה
      עריכה נוכחית:
      27. קוד לשינוי שפת המקלדת לעברית
      28. קוד לייצוא שמות הקבצים מתוך תיקייה

      מושגי יסוד בVBA

      נא לא לשאול שאלות

      1. אני לא הולך להסביר פה איך ליצור מודול ולפתוח את הvba לזה תעשו שיעורי בית לבד.

      2. כל קוד חייב להיות בתוך sub עם שם

      3. בניית מאקרו הוא בעצם במו בניית פאזל, לפאזל הזה יש שלושה סוגי חלקים: אובייקטים הגדרות ופעולות.
        אובייקטים הם חלקי המסמך כגון פיסקאות וכו'. הגדרות הם הגדרות הפיסקה או הגופן וכו'. ופעולות הם פעולות שנעשה עם האובייקט כגון להעתיק אותו.
        דוגמא: selection.delete זוהי פעולה מחיקה על הטקסט המסומן
        "Selection.font.Name = "Arial זוהי פעולה שמגדירה את שם הפונט של הטקסט המסומן ל- Arial
        פעולות באות אחרי נקודה. מאפיינים באים אחרי =

      4. הגדרת משתנים כמה כללים טובים:
        שם המשתנה חייב להתחיל באות
        אין להוסיף רווחים לשם המשתנה
        אין לתת למשתנה שם זהה לשם המאקרו
        אין לתת למשתנים שמות שמורים כגון Save
        מומלץ לתת שם המתאר באופן מדויק את משמעות המשתנה

      5. משתנה מוגדר על ידי Dim "שם המשתנה" As "סוג המשתנה"
        לדוגמא Dim MyString As String משתנה בשם MyString שהוגדר כמחרוזת טקסט

      6. סוגי משתנים
        Integer - מאפשר לאחסן בתוכו מספרים שלמים
        long - כמו integer רק עבור מספרים גדולים מ32,000
        Double - מאפשר לאחסן בתוכו מספרים עשרוניים
        String - מאפשר לאחסן בתוכו מחרוזת טקסט
        Range - מאפשר לאחסן בתוכו טווחים
        כמו"כ כל אובייקט במסמך יכול להיות משתנה ג"כ

      7. אחרי Dim - הכרזה של המשתנה יש לתת לו ערך
        לדוגמא
        Dim Mystring As String
        "Mystring = "abc
        הערה הזנה של טקסט צמיד תהיה בתוך מירכאות משא"כ במספרים.
        בקביעת משתני טווח יש להוסיף את המילה set
        לדוגמא
        Dim myrange As Range
        Set myrange = Selection.range
        המשתנה של הטווח הוגדר כטווח הטקסט המסומן

      P מנותק
      P מנותק
      pcinfogmach
      מדריכים
      כתב ב נערך לאחרונה על ידי
      #15

      קוד להוספת כותרות צד

      Option Explicit
      Sub כותרות_צד()
      
      
      Dim numColumns As Integer, currentPara As Paragraph, slctd As Range _
              
      'set range
      Set slctd = Selection.Range
      
      'start loop
      For Each currentPara In slctd.Paragraphs
      Application.ScreenUpdating = False
      currentPara.Range.Select
      
      'get column width
          numColumns = ActiveDocument.PageSetup.TextColumns.Count
          If numColumns = 2 Then
              Dim columnWidth As Single
              Dim columnWidth2 As Single
              columnWidth = ActiveDocument.PageSetup.TextColumns.Item(1).Width
              columnWidth2 = ActiveDocument.PageSetup.TextColumns.Item(2).Width
          End If
          
      'exceptions
      If Not currentPara.Range.ComputeStatistics(wdStatisticLines) > 1 _
      Or Not currentPara.Range.ComputeStatistics(wdStatisticLines) > 2 Then GoTo nxt
      
      'Get the first sentence of the current paragraph
          Dim firstSentence As String
          Dim words() As String
          words = Split(currentPara.Range.Text, " ")
          firstSentence = words(0) & " " & words(1) & " " & words(2) & " " _
          & words(3) & " " & words(4) & " " & words(5)
          
      'get font size set box font size and calc misalignment adjustment accordingly
          Dim fontSize, x, y, z As Single
          fontSize = currentPara.Range.Font.SizeBi - 4
          x = currentPara.Range.Font.SizeBi
          y = x - 8
          z = y * 0.4
          'MsgBox z
      
      '
      'Dim spaceWidth As Double
      'spaceWidth = currentPara.Range.font.spacing
      'Dim spaceWidth As Double
      'spaceWidth = ActiveDocument.PageSetup.TextColumns.spacing / 2
      '
          
          'get middle of page
          Dim mrgn As Double
          mrgn = ActiveDocument.PageSetup.LeftMargin / 2
      
          Dim newShape As Shape
          'left column - if para calc is smaller then middle of page
          If ActiveDocument.PageSetup.PageWidth / 2 > currentPara.Range.Information(wdHorizontalPositionRelativeToPage) Then
          Set newShape = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                  Left:=currentPara.Range.Information(wdHorizontalPositionRelativeToPage) - columnWidth2 - mrgn, _
                  Top:=currentPara.Range.Information(wdVerticalPositionRelativeToPage), _
                  Width:=mrgn, Height:=50)
              newShape.TextFrame.TextRange.ParagraphFormat.Alignment = wdAlignParagraphRight
              End If
              
          'right column - if para calc is larger
          If ActiveDocument.PageSetup.PageWidth / 2 < currentPara.Range.Information(wdHorizontalPositionRelativeToPage) Then
              Set newShape = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                  Left:=currentPara.Range.Information(wdHorizontalPositionRelativeToPage), _
                  Top:=currentPara.Range.Information(wdVerticalPositionRelativeToPage), _
                  Width:=mrgn, Height:=50)
          newShape.TextFrame.TextRange.ParagraphFormat.Alignment = wdAlignParagraphLeft
         
          End If
             'newShape.TextFrame.MarginLeft = 0
             'newShape.TextFrame.MarginRight = 0
              newShape.TextFrame.MarginTop = z 'adjust misalignment
              newShape.TextFrame.MarginBottom = 0
              newShape.Line.Visible = msoFalse
              newShape.TextFrame.TextRange.Text = firstSentence
              newShape.TextFrame.TextRange.Font.SizeBi = 8
              newShape.TextFrame.AutoSize = True
              
      
          'tiny adjustment
              If ActiveDocument.PageSetup.PageWidth / 2 > currentPara.Range.Information(wdHorizontalPositionRelativeToPage) Then
              newShape.TextFrame.MarginTop = newShape.TextFrame.MarginTop - 0.1
              Else
              newShape.TextFrame.MarginTop = newShape.TextFrame.MarginTop - 0.05
              newShape.TextFrame.MarginLeft = newShape.TextFrame.MarginLeft + 0.04
              End If
              
      nxt:
      Application.ScreenUpdating = True
      Application.ScreenRefresh
          Next currentPara
          
          End Sub
          
      Sub מחק_כותרת_צד_בכל_המסמך()
          Dim shp As Shape, i As Integer, shppos, mrgnright, mrgnleft As Single
              
              mrgnleft = ActiveDocument.PageSetup.LeftMargin
              mrgnright = ActiveDocument.PageSetup.PageWidth - mrgnleft
          
          For i = ActiveDocument.Shapes.Count To 1 Step -1
              Set shp = ActiveDocument.Shapes(i)
              shppos = shp.TextFrame.TextRange.Information(wdHorizontalPositionRelativeToPage)
              
              If shppos > mrgnright Or shppos < mrgnleft _
              And shp.Type = msoTextBox And shp.Line.Visible = msoFalse Then
               'And shp.Width = ActiveDocument.PageSetup.LeftMargin / 2 Then
                  shp.Delete
              End If
          
          Next i
          End Sub
      
      Sub מחק_כותרות_צד_בעמוד_זה()
      Dim shp As Shape, i, currentPage As Integer, _
      shppos, mrgnright, mrgnleft As Single
          
          mrgnleft = ActiveDocument.PageSetup.LeftMargin
          mrgnright = ActiveDocument.PageSetup.PageWidth - mrgnleft
          
          currentPage = Selection.Information(wdActiveEndPageNumber)
          Application.ScreenUpdating = False
          For Each shp In ActiveDocument.Shapes
              shppos = shp.TextFrame.TextRange.Information(wdHorizontalPositionRelativeToPage)
              If shp.Anchor.Information(wdActiveEndPageNumber) = currentPage And _
              shppos > mrgnright Or shppos < mrgnleft _
              And shp.Type = msoTextBox And shp.Line.Visible = msoFalse _
              And shp.Anchor.Information(wdActiveEndPageNumber) = currentPage Then
                  shp.Select (False)
              End If
          Next shp
          Application.ScreenUpdating = True
          Selection.Delete Unit:=wdCharacter, Count:=1
      End Sub
      
      
      
      
      
      
      
      menajemmendelM תגובה 1 תגובה אחרונה
      1
      • ד דאנציג

        @pcinfogmach
        הגדלה / הקטנה בחצי נקודה על טקסט נבחר. -רק כאשר הבחירה באותו גודל, וכאן המקום לבקש מי שיודע כיצד ניתן שהפונקציה תעבוד גם על מספר גדלים תע"ב אם ישתף את הציבור.

        Sub הגדלה_בחצי_נקודה()
            Selection.Font.SizeBi = Selection.Font.SizeBi + 0.5
        End Sub
        Sub הקטנה_בחצי_נקודה()
            Selection.Font.SizeBi = Selection.Font.SizeBi - 0.5
        End Sub
        
        
        מ מנותק
        מ מנותק
        מאקרו
        כתב ב נערך לאחרונה על ידי
        #16

        @דאנציג כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:

        וכאן המקום לבקש מי שיודע כיצד ניתן שהפונקציה תעבוד גם על מספר גדלים תע"ב אם ישתף את הציבור.

        שתי אפשרויות:
        א. לעשות לולאה שעוברת על כל התווים, המעלה שהכל יהיה במידה מדוייקת, החסרון שהפעולה תהיה מאד איטית בטקסט ארוך.
        ב. להגדיר את הכל לפי התו הראשון בבחירה, המעלה שפועל בצורה מהירה, החסרון שההגדלה לא תהיה מדוייקת וזה רק נותן פתרון שלא יחזיר שגיאה.
        אפשר לעשות ג"כ בדיקה האם מחזיר שגיאה ואז שיעבוד בלולאה...

        תגובה 1 תגובה אחרונה
        1
        • P pcinfogmach

          אינצקלופדיה שיתופית למאקרו (VBA)

          פוסט זה נועד כדי לשתף קטעי קוד מוצלחים עבור פונקציות שונות במאקרו (VBA) עבור תוכנת מיקרוסופט וורד.
          הציבור מוזמן לשתף 🙂
          נ.ב. אינני מתכנן לענות על שאלות רק להעלות קטעי קוד שימושיים

          1. קוד לסימון המילה הראשונה בפיסקה בכל המסמך
          2. קוד להוספת צורה במיקום הנוכחי של הסמן במסמך
          3. איך לעשות פעולות נסתרות מעיני המשתמש - ולהגביר את מהירות הקוד
          4. קוד להתקנת תבנית בתוך תיקיית ההתחלה של וורד
          5. קוד ליצירת לולאה - עד מילוי תנאי מסויים
          6. קוד להוספת סגנון והסרתו
          7. לולאה שחוזרת על עצמה מספר פעמים קצוב
          8. טיפול בשגיאות
          9. אינטראקציה עם המשתמש בצורה יעילה - כן, לא, או ביטול. (יצירת תנאים לפי בחירת המשתמש).
          10. איך לשנות את תחום הטקסט המסומן

          11.קוד לפתיחת מסמך קובץ תיקייה או אתר אינטרנט
          12. קוד עיצוב פיסקה כנהוג בספרי קודש, חלון, מילה ראשונה, ומרכוז שורה אחרונה
          13. הגדלה והקטנה בחצי נקודה על טקסט נבחר
          14. כותרות צד
          15.כמה מוסכמויות בכתיבת קוד:
          16. מה עושים כאשר הטקסט בתוך userform לא מופיע
          17.חיפוש והחלפה במסמכים מרובים
          18. פתיחת מסמכים מרובים
          19. הכנסת טקסט נבחר (כגון מראה מקום) לתוך סוגריים.
          20.הערות ברצף ו - הסרת הערות ברצף
          21. הקטנת והגדלת סוגריים
          22. איך ליצור userform - מדריך
          23.הגדל רווחים בין מילים
          23.הסרת כל הרווחים בטקסט שסומן
          24. איך ליצור range נפרד עבור כל טור בהערות שוליים
          25. שינוי מרווח בין טורים רק בהערות שוליים
          26. קוד חמוד להעתקת כל המודולים מתבנית אחת לשניה
          עריכה נוכחית:
          27. קוד לשינוי שפת המקלדת לעברית
          28. קוד לייצוא שמות הקבצים מתוך תיקייה

          מושגי יסוד בVBA

          נא לא לשאול שאלות

          1. אני לא הולך להסביר פה איך ליצור מודול ולפתוח את הvba לזה תעשו שיעורי בית לבד.

          2. כל קוד חייב להיות בתוך sub עם שם

          3. בניית מאקרו הוא בעצם במו בניית פאזל, לפאזל הזה יש שלושה סוגי חלקים: אובייקטים הגדרות ופעולות.
            אובייקטים הם חלקי המסמך כגון פיסקאות וכו'. הגדרות הם הגדרות הפיסקה או הגופן וכו'. ופעולות הם פעולות שנעשה עם האובייקט כגון להעתיק אותו.
            דוגמא: selection.delete זוהי פעולה מחיקה על הטקסט המסומן
            "Selection.font.Name = "Arial זוהי פעולה שמגדירה את שם הפונט של הטקסט המסומן ל- Arial
            פעולות באות אחרי נקודה. מאפיינים באים אחרי =

          4. הגדרת משתנים כמה כללים טובים:
            שם המשתנה חייב להתחיל באות
            אין להוסיף רווחים לשם המשתנה
            אין לתת למשתנה שם זהה לשם המאקרו
            אין לתת למשתנים שמות שמורים כגון Save
            מומלץ לתת שם המתאר באופן מדויק את משמעות המשתנה

          5. משתנה מוגדר על ידי Dim "שם המשתנה" As "סוג המשתנה"
            לדוגמא Dim MyString As String משתנה בשם MyString שהוגדר כמחרוזת טקסט

          6. סוגי משתנים
            Integer - מאפשר לאחסן בתוכו מספרים שלמים
            long - כמו integer רק עבור מספרים גדולים מ32,000
            Double - מאפשר לאחסן בתוכו מספרים עשרוניים
            String - מאפשר לאחסן בתוכו מחרוזת טקסט
            Range - מאפשר לאחסן בתוכו טווחים
            כמו"כ כל אובייקט במסמך יכול להיות משתנה ג"כ

          7. אחרי Dim - הכרזה של המשתנה יש לתת לו ערך
            לדוגמא
            Dim Mystring As String
            "Mystring = "abc
            הערה הזנה של טקסט צמיד תהיה בתוך מירכאות משא"כ במספרים.
            בקביעת משתני טווח יש להוסיף את המילה set
            לדוגמא
            Dim myrange As Range
            Set myrange = Selection.range
            המשתנה של הטווח הוגדר כטווח הטקסט המסומן

          P מנותק
          P מנותק
          pcinfogmach
          מדריכים
          כתב ב נערך לאחרונה על ידי
          #17

          @OdedDvir כתב באקסס למתחילים: יצירת מערכת לניהול תורמים:
          כמה מוסכמויות בכתיבת קוד:

          עבור שמות פונקציות יש להשתמש ב upper camel case, או בתרגום חופשי: כתיבת גמל (?) או כתיבה גמלונית(?) 🤦 , דהיינו להתחיל כל מילה בשם הפונקציה באות גדולה, למשל:
          ()GetUserName
          או
          ()CleanMyDesk

          עבור שמות משתנים או שמות פרמטרים (לפונקציה) על ידי lower camel case דהיינו להתחיל כל מילה באות גדולה, למעט המילה הראשונה בשם המשתנה, שמתחילה באות קטנה, למשל:
          donationsToUpdate
          או
          MakeMeSomeCoffee(addSugar As Boolean, numberOfCups As Long)

          למרות ש-VBA לא תמיד שומרת על מוסכמויות אלו בעצמה (נו נו נו VBA...), כדאי להתרגל בהן כבר מתחילת הדרך. הדבר ישתלם בהמשך, כשנלמד עוד מוסכמויות או נרצה לעבור לשפה אחרת.

          תגובה 1 תגובה אחרונה
          1
          • P מנותק
            P מנותק
            pcinfogmach
            מדריכים
            כתב ב נערך לאחרונה על ידי
            #18

            לפעמים כאשר משתמשים בuserform בתצורה של modeless הטקסט שבתוך ה userform לא נראה בהרצה במקרה כזה יש לקרוא לuserform כך:
            Userform1.Show
            Userform1.Repaint

            1 תגובה 1 תגובה אחרונה
            0
            • P pcinfogmach

              לפעמים כאשר משתמשים בuserform בתצורה של modeless הטקסט שבתוך ה userform לא נראה בהרצה במקרה כזה יש לקרוא לuserform כך:
              Userform1.Show
              Userform1.Repaint

              1 מנותק
              1 מנותק
              121244
              כתב ב נערך לאחרונה על ידי
              #19
              פוסט זה נמחק!
              P תגובה 1 תגובה אחרונה
              0
              • 1 121244

                פוסט זה נמחק!

                P מנותק
                P מנותק
                pcinfogmach
                מדריכים
                כתב ב נערך לאחרונה על ידי
                #20
                פוסט זה נמחק!
                תגובה 1 תגובה אחרונה
                0
                • P מנותק
                  P מנותק
                  pcinfogmach
                  מדריכים
                  כתב ב נערך לאחרונה על ידי pcinfogmach
                  #21

                  חיפוש והחלפה במסמכים מרובים לפי תיקיות

                  Sub SearchReplaceAllDocumentsInFolder()
                      Dim FolderPath As String
                      Dim FileName As String
                      Dim DocumentPath As String
                      Dim doc As Document
                      Dim Counter As Long
                          
                      ' Select the folder containing the documents
                      With Application.FileDialog(msoFileDialogFolderPicker)
                          .Title = "Select Folder"
                          If .Show = -1 Then
                              FolderPath = .SelectedItems(1) & "\"
                          Else
                              Exit Sub
                          End If
                      End With
                      
                      ' Disable screen updating for faster execution
                      Application.ScreenUpdating = False
                      
                      ' Initialize counters
                      Counter = 0
                      
                      ' Loop through each file in the folder
                      FileName = Dir(FolderPath & "*.doc*")
                      Do While FileName <> ""
                          ' Construct the full path of the document
                          DocumentPath = FolderPath & FileName
                          
                          ' Open the document
                          Set doc = Documents.Open(FileName:=DocumentPath)
                          
                          ' Perform the search and replace
                          With doc.Content.Find
                              .ClearFormatting
                              .text = "הזן כאן את הטקסט לחיפוש" ' Replace "SearchText" with your desired search text
                              .Replacement.ClearFormatting
                              .Replacement.text = "הזן כאן את הטקסט להחלפה" ' Replace "ReplaceText" with your desired replacement text
                              .Execute Replace:=wdReplaceAll
                               End With
                          
                          ' Save and close the document
                          doc.Close SaveChanges:=True
                          
                          ' Increment counter
                          Counter = Counter + 1
                          
                          ' Move to the next file
                          FileName = Dir
                      Loop
                      
                      ' Enable screen updating
                      Application.ScreenUpdating = True
                      
                      ' Display results
                      MsgBox "Search and Replace completed." & vbCrLf & _
                          "Total Documents Processed: " & Counter
                  End Sub
                  

                  עריכה:
                  חיפוש והחלפה במסמכים מרובים לפי בחירת קבצים:

                  Sub SearchReplaceAllDocuments()
                      Dim FileDialog As FileDialog
                      Dim FilePaths As Variant
                      Dim FileName As Variant
                      Dim srchtxt As String, rplctxt As String
                      Dim doc As Document, Counter As Long
                      Dim wldcrds As VbMsgBoxResult, srchwldcrds As Boolean
                      
                     wldcrds = MsgBox("האם ברצונך להשתמש עם תווים כלליים בחיפוש זה?", vbYesNoCancel + vbMsgBoxRight + vbMsgBoxRtlReading + vbQuestion, "חיפוש והחלפה במסמכים מרובים")
                      If wldcrds = vbYes Then srchwldcrds = True
                      If wldcrds = vbNo Then srchwldcrds = False
                      If wldcrds = vbCancel Then Exit Sub
                        
                      srchtxt = InputBox("הזן טקסט או קוד לחיפוש", "חיפוש והחלפה במסמכים מרובים")
                      rplctxt = InputBox("הזן טקסט או קוד להחלפה", "חיפוש והחלפה במסמכים מרובים")
                      
                      ' Open the file picker dialog
                      Set FileDialog = Application.FileDialog(msoFileDialogFilePicker)
                      With FileDialog
                          .Title = "בחר קבצים (חיפוש בקבצים מרובים לפי בחירת קבצים)"
                          .AllowMultiSelect = True
                          .Filters.Clear
                          .Filters.Add "Word Documents", "*.doc*"
                          If .Show = -1 Then
                  '            FilePaths = .SelectedItems
                          
                      
                      ' Disable screen updating for faster execution
                      Application.ScreenUpdating = False
                      
                      ' Initialize counter
                      Counter = 0
                      
                      ' Loop through each selected file
                      For Each FileName In .SelectedItems
                          ' Open the document
                          Set doc = Documents.Open(FileName:=FileName)
                          
                          ' Perform the search and replace
                          With doc.Content.Find
                              .ClearFormatting
                              .Text = srchtxt
                              .Replacement.ClearFormatting
                              .Replacement.Text = rplctxt
                              .MatchWildcards = srchwldcrds
                              .Execute Replace:=wdReplaceAll
                          End With
                          
                          ' Save and close the document
                          doc.Close SaveChanges:=True
                          
                          ' Increment counter
                          Counter = Counter + 1
                      Next FileName
                      
                      ' Enable screen updating
                      Application.ScreenUpdating = True
                      
                      ' Display results
                       ' Display results
                      MsgBox "פעולת ההחלפה הסתיימה." & vbCrLf & _
                          "מספר המסמכים שבוצע בהם החלפה הם: " & Counter, vbMsgBoxRight, vbMsgBoxRtlReading, "הפעולה הסתיימה"
                              
                          End If
                      End With
                  End Sub
                  

                  עריכה שניה:
                  עכשיו מצאתי את זה
                  https://wordmvp.com/FAQs/MacrosVBA/BatchFR.htm
                  יש שם הרבה רעיונות עבור שיפור הקוד

                  תגובה 1 תגובה אחרונה
                  1
                  • P מנותק
                    P מנותק
                    pcinfogmach
                    מדריכים
                    כתב ב נערך לאחרונה על ידי
                    #22

                    פתיחת מסמכים מרובים

                    Sub OpenAllDocumentsInFolder()
                        Dim FolderPath As String
                        Dim FileName As String
                        Dim DocumentPath As String
                        
                        ' Select the folder containing the documents
                        With Application.FileDialog(msoFileDialogFolderPicker)
                            .Title = "Select Folder"
                            If .Show = -1 Then
                                FolderPath = .SelectedItems(1) & "\"
                            Else
                                Exit Sub
                            End If
                        End With
                        
                        ' Disable screen updating for faster execution
                        Application.ScreenUpdating = False
                        
                        ' Loop through each file in the folder
                        FileName = Dir(FolderPath & "*.doc*")
                        Do While FileName <> ""
                            ' Construct the full path of the document
                            DocumentPath = FolderPath & FileName
                            
                            ' Open the document
                            Documents.Open FileName:=DocumentPath
                            
                            ' Move to the next file
                            FileName = Dir
                        Loop
                        
                        ' Enable screen updating
                        Application.ScreenUpdating = True
                    End Sub
                    
                    1 תגובה 1 תגובה אחרונה
                    0
                    • P pcinfogmach

                      פתיחת מסמכים מרובים

                      Sub OpenAllDocumentsInFolder()
                          Dim FolderPath As String
                          Dim FileName As String
                          Dim DocumentPath As String
                          
                          ' Select the folder containing the documents
                          With Application.FileDialog(msoFileDialogFolderPicker)
                              .Title = "Select Folder"
                              If .Show = -1 Then
                                  FolderPath = .SelectedItems(1) & "\"
                              Else
                                  Exit Sub
                              End If
                          End With
                          
                          ' Disable screen updating for faster execution
                          Application.ScreenUpdating = False
                          
                          ' Loop through each file in the folder
                          FileName = Dir(FolderPath & "*.doc*")
                          Do While FileName <> ""
                              ' Construct the full path of the document
                              DocumentPath = FolderPath & FileName
                              
                              ' Open the document
                              Documents.Open FileName:=DocumentPath
                              
                              ' Move to the next file
                              FileName = Dir
                          Loop
                          
                          ' Enable screen updating
                          Application.ScreenUpdating = True
                      End Sub
                      
                      1 מנותק
                      1 מנותק
                      106
                      כתב ב נערך לאחרונה על ידי 106
                      #23

                      הכנסת טקסט נבחר (כגון מראה מקום) לתוך סוגריים.

                      Sub parenthesis()
                      With Selection.Range
                      .InsertBefore "("
                      .InsertAfter ")"
                      End With
                      End Sub
                      
                      ד תגובה 1 תגובה אחרונה
                      2
                      • 1 106

                        הכנסת טקסט נבחר (כגון מראה מקום) לתוך סוגריים.

                        Sub parenthesis()
                        With Selection.Range
                        .InsertBefore "("
                        .InsertAfter ")"
                        End With
                        End Sub
                        
                        ד מנותק
                        ד מנותק
                        דאנציג
                        כתב ב נערך לאחרונה על ידי דאנציג
                        #24

                        @106
                        @dmp הביא פה בעבר הקוד הזה:

                        
                        '
                        ' סוגריים_עגולות Macro
                        '
                        '
                        Selection.Text = "(" & Selection.Text & ")"
                        End Sub
                        

                        וכאן המקום לשאול, כיצד ניתן להרחיב את הסוגריים עד סוף המילה אפילו כאשר עומדים באמצעה.

                        מ תגובה 1 תגובה אחרונה
                        1
                        • ד דאנציג

                          @106
                          @dmp הביא פה בעבר הקוד הזה:

                          
                          '
                          ' סוגריים_עגולות Macro
                          '
                          '
                          Selection.Text = "(" & Selection.Text & ")"
                          End Sub
                          

                          וכאן המקום לשאול, כיצד ניתן להרחיב את הסוגריים עד סוף המילה אפילו כאשר עומדים באמצעה.

                          מ מנותק
                          מ מנותק
                          מאקרו
                          כתב ב נערך לאחרונה על ידי
                          #25

                          @דאנציג

                          
                          Selection.MoveEndWhile Cset:=" ", Count:=wdBackward
                          Selection.InsertAfter (")")
                          Selection.InsertBefore ("(")
                          
                          
                          ד תגובה 1 תגובה אחרונה
                          2
                          • מ מאקרו

                            @דאנציג

                            
                            Selection.MoveEndWhile Cset:=" ", Count:=wdBackward
                            Selection.InsertAfter (")")
                            Selection.InsertBefore ("(")
                            
                            
                            ד מנותק
                            ד מנותק
                            דאנציג
                            כתב ב נערך לאחרונה על ידי
                            #26

                            @מאקרו
                            לא עובד לי.

                            יש לציין לתוסף המוצלח הזה שעושה זאת נפלא.

                            P תגובה 1 תגובה אחרונה
                            1
                            • ד דאנציג

                              @מאקרו
                              לא עובד לי.

                              יש לציין לתוסף המוצלח הזה שעושה זאת נפלא.

                              P מנותק
                              P מנותק
                              pcinfogmach
                              מדריכים
                              כתב ב נערך לאחרונה על ידי pcinfogmach
                              #27

                              @דאנציג כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:

                              וכאן המקום לשאול, כיצד ניתן להרחיב את הסוגריים עד סוף המילה אפילו כאשר עומדים באמצעה.

                              Selection.MoveEndUntil Cset:=" ", Count:=wdForward
                              Selection.MoveStartUntil Cset:=" ", Count:=wdBackward
                              Selection.text = "(" & Selection.text & ")"
                              

                              או אפשר ככה למי שמעדיף

                              With Selection
                                  .MoveEndUntil Cset:=" ", Count:=wdForward
                                  .MoveStartUntil Cset:=" ", Count:=wdBackward
                                  .text = "(" & .text & ")"
                              End With
                              

                              משום מה במילים ארוכות באנגלית הוא עושה קצת בעיות 😞

                              תגובה 1 תגובה אחרונה
                              2
                              • P pcinfogmach

                                קוד להוספת כותרות צד

                                Option Explicit
                                Sub כותרות_צד()
                                
                                
                                Dim numColumns As Integer, currentPara As Paragraph, slctd As Range _
                                        
                                'set range
                                Set slctd = Selection.Range
                                
                                'start loop
                                For Each currentPara In slctd.Paragraphs
                                Application.ScreenUpdating = False
                                currentPara.Range.Select
                                
                                'get column width
                                    numColumns = ActiveDocument.PageSetup.TextColumns.Count
                                    If numColumns = 2 Then
                                        Dim columnWidth As Single
                                        Dim columnWidth2 As Single
                                        columnWidth = ActiveDocument.PageSetup.TextColumns.Item(1).Width
                                        columnWidth2 = ActiveDocument.PageSetup.TextColumns.Item(2).Width
                                    End If
                                    
                                'exceptions
                                If Not currentPara.Range.ComputeStatistics(wdStatisticLines) > 1 _
                                Or Not currentPara.Range.ComputeStatistics(wdStatisticLines) > 2 Then GoTo nxt
                                
                                'Get the first sentence of the current paragraph
                                    Dim firstSentence As String
                                    Dim words() As String
                                    words = Split(currentPara.Range.Text, " ")
                                    firstSentence = words(0) & " " & words(1) & " " & words(2) & " " _
                                    & words(3) & " " & words(4) & " " & words(5)
                                    
                                'get font size set box font size and calc misalignment adjustment accordingly
                                    Dim fontSize, x, y, z As Single
                                    fontSize = currentPara.Range.Font.SizeBi - 4
                                    x = currentPara.Range.Font.SizeBi
                                    y = x - 8
                                    z = y * 0.4
                                    'MsgBox z
                                
                                '
                                'Dim spaceWidth As Double
                                'spaceWidth = currentPara.Range.font.spacing
                                'Dim spaceWidth As Double
                                'spaceWidth = ActiveDocument.PageSetup.TextColumns.spacing / 2
                                '
                                    
                                    'get middle of page
                                    Dim mrgn As Double
                                    mrgn = ActiveDocument.PageSetup.LeftMargin / 2
                                
                                    Dim newShape As Shape
                                    'left column - if para calc is smaller then middle of page
                                    If ActiveDocument.PageSetup.PageWidth / 2 > currentPara.Range.Information(wdHorizontalPositionRelativeToPage) Then
                                    Set newShape = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                                            Left:=currentPara.Range.Information(wdHorizontalPositionRelativeToPage) - columnWidth2 - mrgn, _
                                            Top:=currentPara.Range.Information(wdVerticalPositionRelativeToPage), _
                                            Width:=mrgn, Height:=50)
                                        newShape.TextFrame.TextRange.ParagraphFormat.Alignment = wdAlignParagraphRight
                                        End If
                                        
                                    'right column - if para calc is larger
                                    If ActiveDocument.PageSetup.PageWidth / 2 < currentPara.Range.Information(wdHorizontalPositionRelativeToPage) Then
                                        Set newShape = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                                            Left:=currentPara.Range.Information(wdHorizontalPositionRelativeToPage), _
                                            Top:=currentPara.Range.Information(wdVerticalPositionRelativeToPage), _
                                            Width:=mrgn, Height:=50)
                                    newShape.TextFrame.TextRange.ParagraphFormat.Alignment = wdAlignParagraphLeft
                                   
                                    End If
                                       'newShape.TextFrame.MarginLeft = 0
                                       'newShape.TextFrame.MarginRight = 0
                                        newShape.TextFrame.MarginTop = z 'adjust misalignment
                                        newShape.TextFrame.MarginBottom = 0
                                        newShape.Line.Visible = msoFalse
                                        newShape.TextFrame.TextRange.Text = firstSentence
                                        newShape.TextFrame.TextRange.Font.SizeBi = 8
                                        newShape.TextFrame.AutoSize = True
                                        
                                
                                    'tiny adjustment
                                        If ActiveDocument.PageSetup.PageWidth / 2 > currentPara.Range.Information(wdHorizontalPositionRelativeToPage) Then
                                        newShape.TextFrame.MarginTop = newShape.TextFrame.MarginTop - 0.1
                                        Else
                                        newShape.TextFrame.MarginTop = newShape.TextFrame.MarginTop - 0.05
                                        newShape.TextFrame.MarginLeft = newShape.TextFrame.MarginLeft + 0.04
                                        End If
                                        
                                nxt:
                                Application.ScreenUpdating = True
                                Application.ScreenRefresh
                                    Next currentPara
                                    
                                    End Sub
                                    
                                Sub מחק_כותרת_צד_בכל_המסמך()
                                    Dim shp As Shape, i As Integer, shppos, mrgnright, mrgnleft As Single
                                        
                                        mrgnleft = ActiveDocument.PageSetup.LeftMargin
                                        mrgnright = ActiveDocument.PageSetup.PageWidth - mrgnleft
                                    
                                    For i = ActiveDocument.Shapes.Count To 1 Step -1
                                        Set shp = ActiveDocument.Shapes(i)
                                        shppos = shp.TextFrame.TextRange.Information(wdHorizontalPositionRelativeToPage)
                                        
                                        If shppos > mrgnright Or shppos < mrgnleft _
                                        And shp.Type = msoTextBox And shp.Line.Visible = msoFalse Then
                                         'And shp.Width = ActiveDocument.PageSetup.LeftMargin / 2 Then
                                            shp.Delete
                                        End If
                                    
                                    Next i
                                    End Sub
                                
                                Sub מחק_כותרות_צד_בעמוד_זה()
                                Dim shp As Shape, i, currentPage As Integer, _
                                shppos, mrgnright, mrgnleft As Single
                                    
                                    mrgnleft = ActiveDocument.PageSetup.LeftMargin
                                    mrgnright = ActiveDocument.PageSetup.PageWidth - mrgnleft
                                    
                                    currentPage = Selection.Information(wdActiveEndPageNumber)
                                    Application.ScreenUpdating = False
                                    For Each shp In ActiveDocument.Shapes
                                        shppos = shp.TextFrame.TextRange.Information(wdHorizontalPositionRelativeToPage)
                                        If shp.Anchor.Information(wdActiveEndPageNumber) = currentPage And _
                                        shppos > mrgnright Or shppos < mrgnleft _
                                        And shp.Type = msoTextBox And shp.Line.Visible = msoFalse _
                                        And shp.Anchor.Information(wdActiveEndPageNumber) = currentPage Then
                                            shp.Select (False)
                                        End If
                                    Next shp
                                    Application.ScreenUpdating = True
                                    Selection.Delete Unit:=wdCharacter, Count:=1
                                End Sub
                                
                                
                                
                                
                                
                                
                                
                                menajemmendelM מחובר
                                menajemmendelM מחובר
                                menajemmendel
                                כתב ב נערך לאחרונה על ידי menajemmendel
                                #28

                                @pcinfogmach כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:

                                קוד להוספת כותרות צד

                                לא הבנתי מה בדיוק המטרה של זה, מה רע בליצור סגנון במסגרת??

                                P תגובה 1 תגובה אחרונה
                                0
                                • menajemmendelM menajemmendel

                                  @pcinfogmach כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:

                                  קוד להוספת כותרות צד

                                  לא הבנתי מה בדיוק המטרה של זה, מה רע בליצור סגנון במסגרת??

                                  P מנותק
                                  P מנותק
                                  pcinfogmach
                                  מדריכים
                                  כתב ב נערך לאחרונה על ידי
                                  #29
                                  פוסט זה נמחק!
                                  menajemmendelM תגובה 1 תגובה אחרונה
                                  0
                                  • P pcinfogmach

                                    פוסט זה נמחק!

                                    menajemmendelM מחובר
                                    menajemmendelM מחובר
                                    menajemmendel
                                    כתב ב נערך לאחרונה על ידי
                                    #30

                                    @pcinfogmach האם זה מה שאתה רוצה לעשות? 4fb55ffd-2eb6-46e6-8f39-b707ef152974-image.png

                                    P תגובה 1 תגובה אחרונה
                                    1
                                    • menajemmendelM menajemmendel

                                      @pcinfogmach האם זה מה שאתה רוצה לעשות? 4fb55ffd-2eb6-46e6-8f39-b707ef152974-image.png

                                      P מנותק
                                      P מנותק
                                      pcinfogmach
                                      מדריכים
                                      כתב ב נערך לאחרונה על ידי pcinfogmach
                                      #31
                                      פוסט זה נמחק!
                                      תגובה 1 תגובה אחרונה
                                      0
                                      • P מנותק
                                        P מנותק
                                        pcinfogmach
                                        מדריכים
                                        כתב ב נערך לאחרונה על ידי pcinfogmach
                                        #32

                                        הקטנת והגדלת סוגריים
                                        מאחר ומדובר ביוזרפורם אני מעלה את הקובץ במקום קוד
                                        יש לחלץ את כל הקבצים ואז להתקין את הקובץ frm

                                        עריכה: גירסה מעודכנת
                                        MyParenthesis.zip

                                        ד תגובה 1 תגובה אחרונה
                                        0
                                        • P pcinfogmach

                                          הקטנת והגדלת סוגריים
                                          מאחר ומדובר ביוזרפורם אני מעלה את הקובץ במקום קוד
                                          יש לחלץ את כל הקבצים ואז להתקין את הקובץ frm

                                          עריכה: גירסה מעודכנת
                                          MyParenthesis.zip

                                          ד מנותק
                                          ד מנותק
                                          דאנציג
                                          כתב ב נערך לאחרונה על ידי דאנציג
                                          #33

                                          @pcinfogmach כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:

                                          הקטנת והגדלת סוגריים
                                          מאחר ומדובר ביוזרפורם אני מעלה את הקובץ frm במקום קוד
                                          Parenthesis.frm

                                          Errors during load. Refer to
                                          Line 8: Property OleObjectBlob in Parenthesis had an invalid file reference.

                                          P תגובה 1 תגובה אחרונה
                                          0

                                          • התחברות

                                          • אין לך חשבון עדיין? הרשמה

                                          • התחברו או הירשמו כדי לחפש.
                                          • פוסט ראשון
                                            פוסט אחרון
                                          0
                                          • חוקי הפורום
                                          • לא נפתר
                                          • משתמשים
                                          • חיפוש גוגל בפורום
                                          • צור קשר