שיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....
-
פתיחת מסמכים מרובים
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
-
פתיחת מסמכים מרובים
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
-
הכנסת טקסט נבחר (כגון מראה מקום) לתוך סוגריים.
Sub parenthesis() With Selection.Range .InsertBefore "(" .InsertAfter ")" End With End Sub
-
-
Selection.MoveEndWhile Cset:=" ", Count:=wdBackward Selection.InsertAfter (")") Selection.InsertBefore ("(")
-
@מאקרו
לא עובד לי.יש לציין לתוסף המוצלח הזה שעושה זאת נפלא.
@דאנציג כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:
וכאן המקום לשאול, כיצד ניתן להרחיב את הסוגריים עד סוף המילה אפילו כאשר עומדים באמצעה.
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
משום מה במילים ארוכות באנגלית הוא עושה קצת בעיות
-
קוד להוספת כותרות צד
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
@pcinfogmach כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:
קוד להוספת כותרות צד
לא הבנתי מה בדיוק המטרה של זה, מה רע בליצור סגנון במסגרת??
-
@pcinfogmach כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:
קוד להוספת כותרות צד
לא הבנתי מה בדיוק המטרה של זה, מה רע בליצור סגנון במסגרת??
פוסט זה נמחק! -
פוסט זה נמחק!
@pcinfogmach האם זה מה שאתה רוצה לעשות?
-
@pcinfogmach האם זה מה שאתה רוצה לעשות?
פוסט זה נמחק! -
הקטנת והגדלת סוגריים
מאחר ומדובר ביוזרפורם אני מעלה את הקובץ במקום קוד
יש לחלץ את כל הקבצים ואז להתקין את הקובץ frmעריכה: גירסה מעודכנת
MyParenthesis.zip -
הקטנת והגדלת סוגריים
מאחר ומדובר ביוזרפורם אני מעלה את הקובץ במקום קוד
יש לחלץ את כל הקבצים ואז להתקין את הקובץ frmעריכה: גירסה מעודכנת
MyParenthesis.zip@pcinfogmach כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:
הקטנת והגדלת סוגריים
מאחר ומדובר ביוזרפורם אני מעלה את הקובץ frm במקום קוד
Parenthesis.frmErrors during load. Refer to
Line 8: Property OleObjectBlob in Parenthesis had an invalid file reference. -
@pcinfogmach כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:
הקטנת והגדלת סוגריים
מאחר ומדובר ביוזרפורם אני מעלה את הקובץ frm במקום קוד
Parenthesis.frmErrors during load. Refer to
Line 8: Property OleObjectBlob in Parenthesis had an invalid file reference. -
@דאנציג
נראה לי שיש לו קובץ תומך שהיה חסר נסה עכשיו@pcinfogmach
את הקובץ עם הסיומת FRX ויז'ואל בייסיק לא נותן להוסיף עם השגיאה הנ"ל.
הקובץ השני מוסיף את זה:
-
@pcinfogmach
את הקובץ עם הסיומת FRX ויז'ואל בייסיק לא נותן להוסיף עם השגיאה הנ"ל.
הקובץ השני מוסיף את זה:
-
@דאנציג
מצויין כמו שאמרתי ה- frx לא אמור להיות מותקן הוא רק קובץ תומך@pcinfogmach והיכן הוא אמור להיות?
בSTARTUP, או בTemplates?
אגב, זה בדיוק הקובץ של הקטנת והגדלת סוגריים של ניקיוזר, אך אם אני לא נותן לו את פקודת המאקרו, כיצד הוא יפעל? -
@pcinfogmach והיכן הוא אמור להיות?
בSTARTUP, או בTemplates?
אגב, זה בדיוק הקובץ של הקטנת והגדלת סוגריים של ניקיוזר, אך אם אני לא נותן לו את פקודת המאקרו, כיצד הוא יפעל?@דאנציג כתב בשיתוף | אינצקלופדיה שיתופית עבור קודים של מאקרו - איך עושים את....:
@pcinfogmach והיכן הוא אמור להיות?
בSTARTUP, או בTemplates?אם אתה רוצה שיאתחל עם וורד אז בstartup או פשוט תוסיף אותו לתבנית נורמל.
אגב, זה בדיוק הקובץ של הקטנת והגדלת סוגריים של ניקיוזר,
זה דומה אבל לא בדיוק השמטתי חלק מהאפשרויות והוספתי פונקציות ועשיתי קוד חדש, יותר פשוט ונקי.
אך אם אני לא נותן לו את פקודת המאקרו, כיצד הוא יפעל?
צודק
היה עוד בעיה שתוקנה עכשיו עם השם של היוזרפורםולהוסיף בתוך מודול רגיל קוד כזה
Sub Parenthesis() MyParenthesis.Show End Sub
-
הגדל והקטן רווחים בין מילים בפיסקאות שנבחרו
עריכה: הקוד שופץ ונערך מחדש על פי ההצעה של @מאקרו
עריכה2: הקוד שימושי ליישור טורים ,אם חסר שורה בין הטורים אפשר כך להוסיף שורה בלי שיורגש...Option Explicit Sub הגדל_רווחים_בין_מילים() Dim rng, para, spaceRange As Range, i As Integer Set rng = Selection.Range 'loop throgh pragraphs For i = 1 To rng.Paragraphs.Count Set para = rng.Paragraphs(i).Range Set spaceRange = para.Duplicate ' Loop through each space in the selected paragraph Do While spaceRange.InRange(para) spaceRange.MoveStartUntil " " ' Move to the next space If spaceRange.InRange(para) Then _ spaceRange.Characters(1).Font.Spacing = spaceRange.Characters(1).Font.Spacing + 1 spaceRange.MoveStart unit:=wdCharacter, Count:=1 ' Move to the next character Loop Next i End Sub Sub הקטן_רווחים_בין_מילים() Dim rng, para, spaceRange As Range, i As Integer Set rng = Selection.Range 'loop throgh pragraphs For i = 1 To rng.Paragraphs.Count Set para = rng.Paragraphs(i).Range Set spaceRange = para.Duplicate ' Loop through each space in the selected paragraph Do While spaceRange.InRange(para) spaceRange.MoveStartUntil " " ' Move to the next space If spaceRange.InRange(para) Then _ spaceRange.Characters(1).Font.Spacing = spaceRange.Characters(1).Font.Spacing - 1 spaceRange.MoveStart unit:=wdCharacter, Count:=1 ' Move to the next character Loop Next i End Sub
עריכה 3:
והנה קוד בשיטה אחרת לפי ההצעה של @menajemmendel קוד זה נערך על ידי ושופץ בעזרת @מאקרוSub ChangeSpacing() Dim myrange As Range, orange As Range Set myrange = Selection.Range myrange.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End Set orange = ActiveDocument.Range(myrange.Start, myrange.End) With orange .Collapse .MoveUntil cset:=" " .SetRange Start:=.Start, End:=.Start + 1 .Select End With Dim c As Font, rslt As Integer Set c = Selection.Font rslt = c.Spacing + 1 With myrange.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Font.Spacing = rslt .Text = " " .Replacement.Text = "^&" .Forward = False .Wrap = wdFindStop .Format = True End With myrange.Find.Execute Replace:=wdReplaceAll End Sub
-
הסרת כל הרווחים בטקסט שסומן
Sub DeleteSpacesInParagraph() Dim rng As Range ' Set the range to the current paragraph Set rng = Selection.Range ' Remove all spaces rng.text = Replace(rng.text, " ", "") End Sub
-
הגדל והקטן רווחים בין מילים בפיסקאות שנבחרו
עריכה: הקוד שופץ ונערך מחדש על פי ההצעה של @מאקרו
עריכה2: הקוד שימושי ליישור טורים ,אם חסר שורה בין הטורים אפשר כך להוסיף שורה בלי שיורגש...Option Explicit Sub הגדל_רווחים_בין_מילים() Dim rng, para, spaceRange As Range, i As Integer Set rng = Selection.Range 'loop throgh pragraphs For i = 1 To rng.Paragraphs.Count Set para = rng.Paragraphs(i).Range Set spaceRange = para.Duplicate ' Loop through each space in the selected paragraph Do While spaceRange.InRange(para) spaceRange.MoveStartUntil " " ' Move to the next space If spaceRange.InRange(para) Then _ spaceRange.Characters(1).Font.Spacing = spaceRange.Characters(1).Font.Spacing + 1 spaceRange.MoveStart unit:=wdCharacter, Count:=1 ' Move to the next character Loop Next i End Sub Sub הקטן_רווחים_בין_מילים() Dim rng, para, spaceRange As Range, i As Integer Set rng = Selection.Range 'loop throgh pragraphs For i = 1 To rng.Paragraphs.Count Set para = rng.Paragraphs(i).Range Set spaceRange = para.Duplicate ' Loop through each space in the selected paragraph Do While spaceRange.InRange(para) spaceRange.MoveStartUntil " " ' Move to the next space If spaceRange.InRange(para) Then _ spaceRange.Characters(1).Font.Spacing = spaceRange.Characters(1).Font.Spacing - 1 spaceRange.MoveStart unit:=wdCharacter, Count:=1 ' Move to the next character Loop Next i End Sub
עריכה 3:
והנה קוד בשיטה אחרת לפי ההצעה של @menajemmendel קוד זה נערך על ידי ושופץ בעזרת @מאקרוSub ChangeSpacing() Dim myrange As Range, orange As Range Set myrange = Selection.Range myrange.SetRange Selection.Paragraphs.First.Range.Start, Selection.Paragraphs.Last.Range.End Set orange = ActiveDocument.Range(myrange.Start, myrange.End) With orange .Collapse .MoveUntil cset:=" " .SetRange Start:=.Start, End:=.Start + 1 .Select End With Dim c As Font, rslt As Integer Set c = Selection.Font rslt = c.Spacing + 1 With myrange.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Font.Spacing = rslt .Text = " " .Replacement.Text = "^&" .Forward = False .Wrap = wdFindStop .Format = True End With myrange.Find.Execute Replace:=wdReplaceAll End Sub
@pcinfogmach למה בלופ, מה רע לך בחפש והחלף? וכי הוא לא יותר מהיר?