Wordãé¸æç¯å²ã®æ®µè½ã®å é ã¾ãã¯æ«å°¾ã«æå®æåãæ¿å ¥ãã
ææ¸ã®å段è½ã®å
é ãæ«å°¾ã«æåãã¾ã¨ãã¦è¿½å ãããå ´é¢ã£ã¦ããã¾ãããï¼
ã俺ï¼ç§ï¼ã«ãããªå ´é¢ã¯ãªãã£ï¼ãã£ã¦æ¹ã«ã¯ãããããä¸ã®è¨äºã¯ç¡ç¨ã®é·ç©ã§ããä»ã®å ´æã« GoTo ãã¦ä¸ããã
ã¨ãããã¨ã§ãä»åã¯é¸æç¯å²å ã«ããå段è½ï¼ã®å é ã¾ãã¯æ«å°¾ï¼ã«ãã¯ãã使ã£ã¦æå®æåãæ¿å ¥ããã¦ã¿ããã¨æãã¾ãã
å®é¨ã«ååãã¦ããã ãã®ã¯æ¬¡ã®ææ¸ã§ãã
注ï¼éã®å«ã³ã§ã¯ããã¾ããã
Â
ç®æ¬¡
- å段è½ã®å é ã«æå®æåãæ¿å ¥ãã
- å段è½ã®æ«å°¾ã«æå®æåãæ¿å ¥ãã
- å段è½ã®å é ã«ã¯ãªãããã¼ãã®åæåãæ¿å ¥ãã
- å段è½ã®æ«å°¾ã«ã¯ãªãããã¼ãã®åæåãæ¿å ¥ãã
Â
å段è½ã®å é ã«æå®æåãæ¿å ¥ãã
ä»»æã®ç¯å²ãé¸æããç¶æ ã§ãã¯ããå®è¡ããã¯ãå®è¡å¾ã«è¡¨ç¤ºããã InputBox ã§å ¥åããæåãå段è½ã®å é ã«æ¿å ¥ãããããã«ãã¾ãã
Â
ã³ã¼ãã¯ãã¡ãã§ãã
Sub é¸æä¸ã®æ®µè½ã®å é ã«æå®æåãæ¿å ¥ãã() Dim æå®æå As String Dim æ®µè½ As Paragraph æå®æå = InputBox("å é ã«æ¿å ¥ããæåãå ¥åãã¦ä¸ããã") If æå®æå = "" Then Exit Sub End If For Each æ®µè½ In Selection.Paragraphs 段è½.Range.InsertBefore æå®æå Next End Sub
Â
é¸æç¯å²å
ã®æ®µè½ãã¹ã¦ã« For Each ï½Next ã§ã«ã¼ãå¦çãè¡ãããã«ãã¾ãã
ã«ã¼ãå
ã§ã¯ãä¸ã¤ã®æ®µè½ã®ç¯å²ã«å¯¾ã㦠InsertBefore ã§å
é ã«æå®æåãæ¿å
¥ããã¦ãã¾ããããã¯ç°¡åã§ããã
Â
Â
å段è½ã®æ«å°¾ã«æå®æåãæ¿å ¥ãã
èãæ¹ã¯å ã»ã©ã¨åãã§ãããä»åº¦ã¯æå®æåãå段è½ã®æ«å°¾ã«æ¿å ¥ãããããã«ãã¾ãã
Â
ã³ã¼ãã¯ãã¡ãã§ãã
Sub é¸æä¸ã®æ®µè½ã®æ«å°¾ã«æå®æåãæ¿å ¥ãã() Dim æå®æå As String Dim æ®µè½ As Paragraph æå®æå = InputBox("æ«å°¾ã«æ¿å ¥ããæåãå ¥åãã¦ä¸ããã") If æå®æå = "" Then Exit Sub End If For Each æ®µè½ In Selection.Paragraphs ActiveDocument.Range(0, 段è½.Range.End - 1).InsertAfter æå®æå 'æ¹è¡ã®æåã«æ¿å ¥ããã®ããã¤ã³ã Next End Sub
Â
å
ã»ã©ã®ã³ã¼ããã InsertBefore ãã InsertAfter ã«å¤ããã ãã§ã¯ä¸æããããªãã®ã§è¥å¹²å·¥å¤«ãå¿
è¦ã§ãã
ãã®ã¾ã¾ InsertAfter ã«ããã¨æ¹è¡ã®å¾ãï¼ã¤ã¾ã次ã®æ®µè½ã®å
é ï¼ã«æåãæ¿å
¥ããã¦ãã¾ãã¾ãããªã®ã§ Range.End ããï¼ï¼æåã®ä½ç½®ï¼ã¤ã¾ãæ¹è¡ã®åï¼ã«æ¿å
¥ããã¾ãããããã®æã段è½ã® Range ã¯å¼æ°æå®ã§ããªãã®ã§ã ActiveDocument.Range ã使ç¨ãã¾ãã
Â
Â
å段è½ã®å é ã«ã¯ãªãããã¼ãã®åæåãæ¿å ¥ãã
ããããã¯ãã¾ãã§ãã
å段è½ã®å
é ã« InputBox ã®æå®æåã§ã¯ãªããã¯ãªãããã¼ãã®åè¡ã®æåãæ¿å
¥ããã¾ãã
Â
ã³ã¼ãã¯ãã¡ãã§ãã
Sub é¸æä¸ã®æ®µè½ã®å é ã«ã¯ãªãããã¼ãã®ãã¼ã¿ãè²¼ãä»ã() Dim myLib As Object Set myLib = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'åç §è¨å®ãªãã§DataObjectã®ã¤ã³ã¹ã¿ã³ã¹ãçæãã Dim å ¨æåå As String Dim åå²æåå As Variant Dim i As Integer Dim æ®µè½ As Paragraph myLib.GetFromClipboard On Error Resume Next å ¨æåå = myLib.GetText On Error GoTo 0 If å ¨æåå <> "" Then åå²æåå = Split(å ¨æåå, vbCrLf) 'å ¨æååãæ¹è¡ã§åå²ãé åã«æ ¼ç´ãã i = 0 For Each æ®µè½ In Selection.Paragraphs If i <= UBound(åå²æåå) Then 段è½.Range.InsertBefore åå²æåå(i) i = i + 1 Else Exit For End If Next Else MsgBox "ã¯ãªãããã¼ãã«ãã¼ã¿ãããã¾ããï¼" End If End Sub
Â
Â
å段è½ã®æ«å°¾ã«ã¯ãªãããã¼ãã®åæåãæ¿å ¥ãã
å段è½ã®æ«å°¾ã« InputBox ã®æå®æåã§ã¯ãªããã¯ãªãããã¼ãã®åè¡ã®æåãæ¿å ¥ããã¾ãã
Â
ã³ã¼ãã¯ãã¡ãã§ãã
Sub é¸æä¸ã®æ®µè½ã®æ«å°¾ã«ã¯ãªãããã¼ãã®ãã¼ã¿ãè²¼ãä»ã() Dim myLib As Object Set myLib = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'åç §è¨å®ãªãã§DataObjectã®ã¤ã³ã¹ã¿ã³ã¹ãçæãã Dim å ¨æåå As String Dim åå²æåå As Variant Dim i As Integer Dim æ®µè½ As Paragraph myLib.GetFromClipboard On Error Resume Next å ¨æåå = myLib.GetText On Error GoTo 0 If å ¨æåå <> "" Then åå²æåå = Split(å ¨æåå, vbCrLf) 'å ¨æååãæ¹è¡ã§åå²ãé åã«æ ¼ç´ãã i = 0 For Each æ®µè½ In Selection.Paragraphs If i <= UBound(åå²æåå) Then ActiveDocument.Range(0, 段è½.Range.End - 1).InsertAfter åå²æåå(i) 'æ¹è¡ã®æåã«æ¿å ¥ããã®ããã¤ã³ã i = i + 1 Else Exit For End If Next Else MsgBox "ã¯ãªãããã¼ãã«ãã¼ã¿ãããã¾ããï¼" End If End Sub
Â
Â
â»ã³ã¼ãã®ä½¿ç¨æ¹æ³
- SubããEnd Subã¾ã§ãã³ãã¼ããæ¨æºã¢ã¸ã¥ã¼ã«çã«è²¼ãä»ãã¦ä½¿ç¨ãã¦ä¸ããããªãããã¯ãã§å®è¡ããå¦çã¯ãå ã«æ»ãããã¨ãã§ãã¾ãããå®è¡åã«ä¸æ¦ä¿åããããç´ãã®ã§ããç¶æ ã«ãã¦ããã¦ä¸ãããWordã§æ¨æºã¢ã¸ã¥ã¼ã«ã«ã³ã¼ããè²¼ãä»ãã¦ãã¯ãã使ç¨ããæ¹æ³ã¯ãã¡ãã