Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Percent formatted field makes me enter as .10
I have my form field set up as a percent, in Excel I am used to just entering
"10", and it will convert to "10%" or "10.00%", but Word is changing that same entry to "1000%". It makes me enter as ".10", which is just stupid that I have to do that only in Word and nowhere else. Does anyone know a way to change this so I can enter 10 and get 10%? |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Percent formatted field makes me enter as .10
If you want to enter 10 and have it display as 10% you are going to need
perform a calculation on that field which will need vba. The following macro run on exit from the form field in question (which should be set as text type) will allow you to enter 10 to produce 10% and 10.5 to produce 10.5% etc. when you tab out of that field. The macro assumes the field is bookmarked Text1 Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub= Format(sRes / 100, "###.00%") End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lauralee08 wrote: I have my form field set up as a percent, in Excel I am used to just entering "10", and it will convert to "10%" or "10.00%", but Word is changing that same entry to "1000%". It makes me enter as ".10", which is just stupid that I have to do that only in Word and nowhere else. Does anyone know a way to change this so I can enter 10 and get 10%? |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Percent formatted field makes me enter as .10
Lenny he
Graham - I too have the same problem, however, when I copied your code into my module, I started getting errors when trying to run the code. It did not like the second to last End Sub= statement (indicating it could only be used with comments), when I deleted it and ran the code, it did not care for the If sRes = Int(sres) ... at that point, I thought I would come back to the source. I am running Word 2003. Regards "Graham Mayor" wrote: If you want to enter 10 and have it display as 10% you are going to need perform a calculation on that field which will need vba. The following macro run on exit from the form field in question (which should be set as text type) will allow you to enter 10 to produce 10% and 10.5 to produce 10.5% etc. when you tab out of that field. The macro assumes the field is bookmarked Text1 Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub= Format(sRes / 100, "###.00%") End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lauralee08 wrote: I have my form field set up as a percent, in Excel I am used to just entering "10", and it will convert to "10%" or "10.00%", but Word is changing that same entry to "1000%". It makes me enter as ".10", which is just stupid that I have to do that only in Word and nowhere else. Does anyone know a way to change this so I can enter 10 and get 10%? |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Percent formatted field makes me enter as .10
I am not surprised it didn't work - something odd happened there during the
transcribing of the code Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = Replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub is what it should have been. Apologies ) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Lenny wrote: Lenny he Graham - I too have the same problem, however, when I copied your code into my module, I started getting errors when trying to run the code. It did not like the second to last End Sub= statement (indicating it could only be used with comments), when I deleted it and ran the code, it did not care for the If sRes = Int(sres) ... at that point, I thought I would come back to the source. I am running Word 2003. Regards "Graham Mayor" wrote: If you want to enter 10 and have it display as 10% you are going to need perform a calculation on that field which will need vba. The following macro run on exit from the form field in question (which should be set as text type) will allow you to enter 10 to produce 10% and 10.5 to produce 10.5% etc. when you tab out of that field. The macro assumes the field is bookmarked Text1 Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub= Format(sRes / 100, "###.00%") End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lauralee08 wrote: I have my form field set up as a percent, in Excel I am used to just entering "10", and it will convert to "10%" or "10.00%", but Word is changing that same entry to "1000%". It makes me enter as ".10", which is just stupid that I have to do that only in Word and nowhere else. Does anyone know a way to change this so I can enter 10 and get 10%? |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Percent formatted field makes me enter as .10
Graham: the revised code worked perfectly... a question though. When
tabbing from another form field, into the "text1" field, everythings fine as long as you actually enter a number and tab out. If you try to tab thru the field (not entering a number) you get a "run time error (13)". Can this be corrected? Lenny "Graham Mayor" wrote: I am not surprised it didn't work - something odd happened there during the transcribing of the code Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = Replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub is what it should have been. Apologies ) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Lenny wrote: Lenny he Graham - I too have the same problem, however, when I copied your code into my module, I started getting errors when trying to run the code. It did not like the second to last End Sub= statement (indicating it could only be used with comments), when I deleted it and ran the code, it did not care for the If sRes = Int(sres) ... at that point, I thought I would come back to the source. I am running Word 2003. Regards "Graham Mayor" wrote: If you want to enter 10 and have it display as 10% you are going to need perform a calculation on that field which will need vba. The following macro run on exit from the form field in question (which should be set as text type) will allow you to enter 10 to produce 10% and 10.5 to produce 10.5% etc. when you tab out of that field. The macro assumes the field is bookmarked Text1 Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub= Format(sRes / 100, "###.00%") End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lauralee08 wrote: I have my form field set up as a percent, in Excel I am used to just entering "10", and it will convert to "10%" or "10.00%", but Word is changing that same entry to "1000%". It makes me enter as ".10", which is just stupid that I have to do that only in Word and nowhere else. Does anyone know a way to change this so I can enter 10 and get 10%? |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Percent formatted field makes me enter as .10
Immediately after the line sRes = oFld("Text1").Result, add this line:
If Len(sRes) = 0 Then Exit Sub If you would rather have 0 appear in the field when you tab through it, use this line instead: If Len(sRes) = 0 Then sRes = "0" -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. Lenny wrote: Graham: the revised code worked perfectly... a question though. When tabbing from another form field, into the "text1" field, everythings fine as long as you actually enter a number and tab out. If you try to tab thru the field (not entering a number) you get a "run time error (13)". Can this be corrected? Lenny "Graham Mayor" wrote: I am not surprised it didn't work - something odd happened there during the transcribing of the code Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = Replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub is what it should have been. Apologies ) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Lenny wrote: Lenny he Graham - I too have the same problem, however, when I copied your code into my module, I started getting errors when trying to run the code. It did not like the second to last End Sub= statement (indicating it could only be used with comments), when I deleted it and ran the code, it did not care for the If sRes = Int(sres) ... at that point, I thought I would come back to the source. I am running Word 2003. Regards "Graham Mayor" wrote: If you want to enter 10 and have it display as 10% you are going to need perform a calculation on that field which will need vba. The following macro run on exit from the form field in question (which should be set as text type) will allow you to enter 10 to produce 10% and 10.5 to produce 10.5% etc. when you tab out of that field. The macro assumes the field is bookmarked Text1 Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub= Format(sRes / 100, "###.00%") End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lauralee08 wrote: I have my form field set up as a percent, in Excel I am used to just entering "10", and it will convert to "10%" or "10.00%", but Word is changing that same entry to "1000%". It makes me enter as ".10", which is just stupid that I have to do that only in Word and nowhere else. Does anyone know a way to change this so I can enter 10 and get 10%? |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Percent formatted field makes me enter as .10
Jay: works like a charm! regards, Lenny
"Jay Freedman" wrote: Immediately after the line sRes = oFld("Text1").Result, add this line: If Len(sRes) = 0 Then Exit Sub If you would rather have 0 appear in the field when you tab through it, use this line instead: If Len(sRes) = 0 Then sRes = "0" -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. Lenny wrote: Graham: the revised code worked perfectly... a question though. When tabbing from another form field, into the "text1" field, everythings fine as long as you actually enter a number and tab out. If you try to tab thru the field (not entering a number) you get a "run time error (13)". Can this be corrected? Lenny "Graham Mayor" wrote: I am not surprised it didn't work - something odd happened there during the transcribing of the code Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = Replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub is what it should have been. Apologies ) -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Lenny wrote: Lenny he Graham - I too have the same problem, however, when I copied your code into my module, I started getting errors when trying to run the code. It did not like the second to last End Sub= statement (indicating it could only be used with comments), when I deleted it and ran the code, it did not care for the If sRes = Int(sres) ... at that point, I thought I would come back to the source. I am running Word 2003. Regards "Graham Mayor" wrote: If you want to enter 10 and have it display as 10% you are going to need perform a calculation on that field which will need vba. The following macro run on exit from the form field in question (which should be set as text type) will allow you to enter 10 to produce 10% and 10.5 to produce 10.5% etc. when you tab out of that field. The macro assumes the field is bookmarked Text1 Sub Percentage() Dim oFld As FormFields Dim sRes As String Dim sDec As String Set oFld = ActiveDocument.FormFields sRes = oFld("Text1").Result If InStr(1, sRes, "%") Then sRes = replace(sRes, "%", "") End If If sRes = Int(sRes) Then sDec = "###%" Else sDec = "###.##%" End If oFld("Text1").Result = Format(sRes / 100, sDec) End Sub= Format(sRes / 100, "###.00%") End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org lauralee08 wrote: I have my form field set up as a percent, in Excel I am used to just entering "10", and it will convert to "10%" or "10.00%", but Word is changing that same entry to "1000%". It makes me enter as ".10", which is just stupid that I have to do that only in Word and nowhere else. Does anyone know a way to change this so I can enter 10 and get 10%? |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Word 2007: Set for Double Space, but Enter makes 2.5 spaces | Page Layout | |||
rtf formatted Memo field from Access 07 Mailmerge into Word | Mailmerge | |||
How do I create a form field to contain formatted text | Microsoft Word Help | |||
Is there a way to type formatted text into a form field? | Microsoft Word Help | |||
formatting percent field using mail merge | Mailmerge |