अंत में मैंने शब्द द्वारा शब्द कॉपी करने का संकल्प किया। स्वरूपित पाठ अंतिम शब्द (कुछ विशेष (स्पष्ट रूप से) वर्णों तक, काफी हद तक काम करना प्रतीत होता था, जहां अचानक सेल जो मैंने कॉपी की गई सामग्री से भरा था, खाली हो जाएगा। जब मैंने कोशिकाओं की संख्या में वृद्धि की, तो अन्य रन-टाइम त्रुटियां पॉप अप हो जाएंगी, जैसे आपकी तालिका दूषित हो गई है, और अन्य संदिग्ध लोग। किसी भी तरह, स्रोत सेल जिसे मैं हमेशा से प्रतिलिपि बना रहा था, एएससीआईआई कोड 13 और 7 के अंत में इन अनोखे वर्णों को अंत में लग रहा था। मुझे पता है कि 13 का मतलब क्या है, लेकिन 7? वैसे भी, मैंने कोड 7 के साथ इस अंतिम चरित्र से अलग सब कुछ कॉपी करने का फैसला किया। ऐसा लगता है कि यह ठीक काम करता है। दोनों स्वरूपण और फ़ील्ड भी कॉपी किए गए हैं। किसी भी मामले में, पूरी कहानी ने मुझे एक और बार साबित कर दिया कि वीबीए में प्रोग्रामिंग ज्यादातर परीक्षण-और-त्रुटि व्यवसाय है। आप कभी भी निश्चित नहीं हैं कि कुछ तोड़ सकता है .. जब तक कि मुझे कुछ महत्वपूर्ण अवधारणाओं पर अद्यतन याद नहीं आ रहा है ..
यहां मेरे द्वारा उपयोग किए गए कोड के भाग हैं। विचार यह है कि पहले हमारे पास एक समृद्ध टेक्स्ट सामग्री के साथ एक एकल 1x1 सेल तालिका वाला दस्तावेज़ है।
(ध्यान दें कि मैं प्रत्येक apostrophe प्रकार वीबी टिप्पणी के सामने // डाल इतना है कि टिप्पणी को सही ढंग से रंग का होगा)
Dim cur_width As Integer, i As Integer, max_cells As Integer, cur_row As Integer
Dim origin_width As Integer
If ActiveDocument.Tables.Count = 1 _
And ActiveDocument.Tables(1).Rows.Count = 1 _
And ActiveDocument.Tables(1).Columns.Count = 1 _
Then
max_cells = 7 //' how many times we are going to "clone" the original content
i = 2 //' current cell count - starting from 2 since the cell with the original content is cell number 1
cur_width = -1 //' current width
cur_row = 1 //' current row count
origin_width = ActiveDocument.Tables(1).Rows(1).Cells(1).Width
//' loop for each row
While i <= max_cells
//' adjust current width
If cur_row = 1 Then
cur_width = origin_width
Else
cur_width = 0
End If
//' loop for each cell - as long as we have space, add cells horizontally
While i <= max_cells And cur_width + origin_width < ActiveDocument.PageSetup.PageWidth
Dim col As Integer
//' \ returns floor() of the result
col = i \ ActiveDocument.Tables(1).Rows.Count
// 'add cell, if it is not already created (which happens when we add rows)
If ActiveDocument.Tables(1).Rows(cur_row).Cells.Count < col Then
ActiveDocument.Tables(1).Rows(cur_row).Cells.Add
End If
// 'adjust new cell width (probably unnecessary
With ActiveDocument.Tables(1).Rows(cur_row).Cells(col)
.Width = origin_width
End With
// 'keep track of the current width
cur_width = cur_width + origin_width
i = i + 1
Wend
//' when we don't have any horizontal space left, add row
If i <= max_cells Then
ActiveDocument.Tables(1).Rows.Add
cur_row = cur_row + 1
End If
Wend
End If
: कोड (एक मैक्रो में किसी एक) के पहले टुकड़े में मैं कोशिकाओं गुणा
//' duplicate the contents of the first cell to other cells
Dim r As Row
Dim c As Cell
Dim b As Boolean
Dim w As Range
Dim rn As Range
b = False
i = 1
For Each r In ActiveDocument.Tables(1).Rows
For Each c In r.Cells
If i <= max_cells Then
// ' don't copy first cell to itself
If b = True Then
//' copy everything word by word
For Each w In ActiveDocument.Tables(1).Rows(1).Cells(1).Range.Words
//' get the last bit of formatted text in the destination cell, as range
//' do it first by getting the whole range of the cell, then collapsing it
//' so that it is now the very end of the cell, and moving it one character
//' before (because collapsing moves the range actually beyond the last character of the range)
Set rn = c.Range
rn.Collapse Direction:=wdCollapseEnd
rn.MoveEnd Unit:=wdCharacter, Count:=-1
//' somehow the last word of the contents of the cell is always Chr(13) & Chr(7)
//' and especially Chr(7) causes some very strange and murky problems
//' I end up avoiding them by not copying the last character, and by setting as a rule
//' that the contents of the first cell should always contain an empty line in the end
If c.Range.Words.Count <> ActiveDocument.Tables(1).Rows(1).Cells(1).Range.Words.Count Then
rn.FormattedText = w
Else
//'MsgBox "The strange text is: " & w.Text
//'the two byte values of this text (which obviously contains special characters with special
//'meaning to Word can be found (and watched) with
//'AscB(Mid(w.Text, 1, 1)) and AscB(Mid(w.Text, 2, 1))
w.MoveEnd Unit:=WdUnits.wdCharacter, Count:=-1
rn.FormattedText = w
End If
Next w
End If
b = True
End If
i = i + 1
Next c
Next r
यहाँ प्रश्न में वर्ड दस्तावेज़ की छवियों हैं:
मैक्रो के दूसरे भाग में मैं पहली बार कक्ष की सामग्री के साथ एक खाली कक्ष को पॉप्युलेट। पहली छवि मैक्रो चलाने से पहले है, दूसरा कोड के पहले हिस्से और आखिरी हिस्से के बीच है, जबकि तीसरी छवि परिणामी दस्तावेज़ है।
Image 1 Image 2 Image 3
यह है कि।
करने के लिए ठीक है, लेकिन यह स्पष्ट हो जाता है कि यह पूरी तरह असमर्थित "ऑफलाइन रूप से डूब गया" नहीं है और जल्द ही या बाद में आपके घटक को असफल कर देगा ... शायद जब आप इसे नहीं चाहते हैं। –
मैं सहमत हूं :) और हाँ, यह हमें कई समस्याएं पैदा करता है। लेकिन आप जानते हैं कि यह कैसा है - हम इसे साल पहले अटक गए थे - और अभी भी इसका समर्थन करना है - बेशक हम भविष्य में उसी दृष्टिकोण का अभ्यास नहीं करेंगे –