Vba word символ пробела

32 / 2 / 0

Регистрация: 31.12.2010

Сообщений: 91

1

добавить пробел

17.02.2011, 11:37. Показов 23493. Ответов 17


Студворк — интернет-сервис помощи студентам

Подскажите, что нужно добавить в следующий код, чтобы между словами в строках Cells(9, 1) и Cells(9, 2) ставился пробел?

«<font face=arial><a href=mailto:» + Worksheets(«Body»).Cells(9, 1) + «>» + Worksheets(«Body»).Cells(9, 1) + «</a></font>» + _
«<font face=arial><b>» + Worksheets(«Body»).Cells(9, 2) + «</b></font><br><br>»



0



195 / 187 / 15

Регистрация: 09.02.2011

Сообщений: 457

17.02.2011, 12:33

3

+ » » + в нужном месте…

вроде для конкатенации лучше использовать & а не +



0



32 / 2 / 0

Регистрация: 31.12.2010

Сообщений: 91

17.02.2011, 13:00

 [ТС]

4

с + » «+ пробовала, не получается



0



11482 / 3773 / 677

Регистрация: 13.02.2009

Сообщений: 11,145

17.02.2011, 13:10

5



0



mc-black

2784 / 716 / 106

Регистрация: 04.02.2011

Сообщений: 1,443

17.02.2011, 13:20

6

Если имеется ввиду пробел, не вызывающий перенос слова, то так:

Visual Basic
1
+ "&nbsp;" +



0



Busine2009

Заблокирован

17.02.2011, 13:23

7

mc-black,
всё, что в кавычках, — является в VBA текстом, т.к. в вашем случае будет просто текст &nbsp;



0



32 / 2 / 0

Регистрация: 31.12.2010

Сообщений: 91

17.02.2011, 15:49

 [ТС]

8

но все таки почему то ни одним из указанных способов не получается поставить пробел между словами.



0



4377 / 661 / 36

Регистрация: 17.01.2010

Сообщений: 2,134

17.02.2011, 16:30

9

dim myStr As string
mystr=Cells(9,1).value & » » & Cells(9,2).Value



0



195 / 187 / 15

Регистрация: 09.02.2011

Сообщений: 457

17.02.2011, 16:54

10

Напишите сюда что у Вас получилось… а лучше не кусок кода весь…



0



32 / 2 / 0

Регистрация: 31.12.2010

Сообщений: 91

17.02.2011, 17:27

 [ТС]

11

спасибо. «&nbsp» помогло, а как сделать двойной или тройной пробел?



0



195 / 187 / 15

Регистрация: 09.02.2011

Сообщений: 457

17.02.2011, 17:49

12

если двойной — это два пробела, то судя по всему «&nbsp&nbsp»



0



Busine2009

Заблокирован

17.02.2011, 19:53

13

Цитата
Сообщение от Bazzy
Посмотреть сообщение

«&nbsp&nbsp»

напишите пример, как это можно применить.



0



mc-black

2784 / 716 / 106

Регистрация: 04.02.2011

Сообщений: 1,443

17.02.2011, 19:55

14

Не совсем так, надо:

Visual Basic
1
+ "&nbsp;&nbsp;" +

Для тех, кто не в курсе, это был фрагмент программной генерации html кода.



0



0 / 0 / 0

Регистрация: 15.03.2016

Сообщений: 105

01.06.2016, 12:34

15

Можно вопрос, как тогда сделать вот это
OOO СК «Шар-М» (ранее ООО ШАР «ИНТЕКС-ШАР»)



0



6875 / 2807 / 533

Регистрация: 19.10.2012

Сообщений: 8,562

01.06.2016, 12:39

16

Ну Вы ведь это уже сделали!



0



0 / 0 / 0

Регистрация: 15.03.2016

Сообщений: 105

01.06.2016, 12:45

17

сделал но без пробелов, в листе1 в ячейке OOO СК «Шар-М» (ранее ООО ШАР «ИНТЕКС-ШАР»)

не пропускает, пусто



0



0 / 0 / 0

Регистрация: 15.03.2016

Сообщений: 105

02.06.2016, 18:39

18

Данная задача решена



0



title keywords f1_keywords ms.prod ms.assetid ms.date ms.localizationpriority

Chr function (Visual Basic for Applications)

vblr6.chm1020927

vblr6.chm1020927

office

a9dc96ec-4719-8d24-144b-61d45fa58fe5

12/11/2019

high

Returns a String containing the character associated with the specified character code.

Syntax

Chr(charcode)
ChrB(charcode)
ChrW(charcode)

The required charcode argument is a Long that identifies a character.

Remarks

Numbers from 0–31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character. The normal range for charcode is 0–255. However, on DBCS systems, the actual range for charcode is -32768–65535.

[!NOTE]
The ChrB function is used with byte data contained in a String. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte.

The ChrW function returns a String containing the Unicode character except on platforms where Unicode is not supported, in which case, the behavior is identical to the Chr function.

[!NOTE]
Visual Basic for the Macintosh does not support Unicode strings. Therefore, ChrW(n) cannot return all Unicode characters for n values in the range of 128–65,535, as it does in the Windows environment. Instead, ChrW(n) attempts a «best guess» for Unicode values n greater than 127. Therefore, you should not use ChrW in the Macintosh environment.

The functions Asc(), AscB(), and AscW() are the opposite of Chr(), ChrB(), and ChrW(). The Asc() functions convert a string to an integer.

Example

This example uses the Chr function to return the character associated with the specified character code.

Dim MyChar
MyChar = Chr(65)    ' Returns A.
MyChar = Chr(97)    ' Returns a.
MyChar = Chr(62)    ' Returns >.
MyChar = Chr(37)    ' Returns %.

See also

  • Character set (0 — 127)
  • Character set (128 — 255)
  • Functions (Visual Basic for Applications)
  • Asc(), AscB(), and AscW() functions

[!includeSupport and feedback]

I hope you can help me.
I have three questions:

  1. In my coding below I am trying to replace «([0-9])( )([A-Za-zÆæØøÅå])» with «1^s3», but the result allways ends like 13^2 or as example «3 A» would become «3A(non-breaking space)», but what I want is «3(non-breaking space)A».
  2. Is there any way I can make ([A-Za-zÆæØøÅå]) to a dynamic word? I have a list of word I want to use instead. Example «3 mg» to «3(non-breaking space)mg» or «1 kilo» to «1(non-breaking space)kilo».
  3. Is there any way I can make a search and replace, where I only replace the «space» with a «non-breaking space» and not the wildcards. The above solution will result in the wildcards being replaced by themselves, this is usually not a problem, but since I am doing this in a dokument that is in tracked changed it will be visable.
Sub NonBreakingSpace(ByVal wordApp As Object, ByVal wordDoc As Object, ByVal myStoryRange As Object)


'With Worksheets("sheet1")
'For Each cell In Range("A3:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
   ' Find1 = cell.Value
   ' Replace1 = cell.Offset(0, 1).Value
    
    For Each myStoryRange In wordDoc.StoryRanges
          With myStoryRange.Find
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = True
            .Text = "([0-9])( )([A-Za-zÆæØøÅå])"
            .Forward = True
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .Replacement.Text = "1^23"
            .Execute Replace:=wdReplaceAll
    End With
    Next myStoryRange
'Next cell
'End With
End Sub

asked Sep 30, 2020 at 14:31

Casper's user avatar

  1. ^s is a non-breaking space, not ^2. You can easily find the symbols required by looking at the text in the advance Find dialog in Word.
  2. Just replace the wildcard characters with a variable containing the word you are looking for. You will need to run a separate search for each Word.
  3. Yes, but you won’t be able to use Replace. You will need to write code to process each match found. There are numerous examples that show how to do this on SO, e.g. Extracting string values containing a certain key word from Word doc to Excel with the page number

answered Oct 1, 2020 at 8:58

Timothy Rylatt's user avatar

Timothy RylattTimothy Rylatt

6,9132 gold badges9 silver badges14 bronze badges

5

Понравилась статья? Поделить с друзьями:
  • Vba word размеры таблицы
  • Vba word размер шрифта
  • Vba word размер таблицы
  • Vba word перевод строки
  • Vba word перебор страниц