Avoid double text when using Select.Bookmark

I have a template were the user should write what department he/she is 
working on. The script works OK with Document_New but if the user is 
miss-spelling or just want to change the name of the department (I do this 
manually in testing mode by running the script again) there will be to 
departments at the bookmark.
I have tried to use a textfield but that disappear after using.
Here is my code (were Enhet is Swedish for Department):

Option Explicit
Dim Enhet As String
Sub Document_New()
    Enhet = InputBox("Vilken avdelning?")
    ActiveDocument.Bookmarks("Enhet").Select
    Selection.TypeText Enhet
End Sub

Someone?

Hasse
0
Utf
11/13/2009 4:02:03 PM
word.vba.general 1023 articles. 1 followers. Follow

2 Replies
876 Views

Similar Articles

[PageSpeed] 27

Hi hassesetter,

Try:
Sub UpdateBookMark()
Dim Enhet As String, BmkRng As Range
Enhet = InputBox("Vilken avdelning?")
 If ActiveDocument.Bookmarks.Exists("Enhet") Then
  Set BmkRng = ActiveDocument.Bookmarks("Enhet").Range
  BmkRng.Text = Enhet
  ActiveDocument.Bookmarks.Add "Enhet", BmkRng
 Else
  MsgBox "Bookmark: Enhet not found."
 End If
Set BmkRng = Nothing
End Sub

Note that there is no need for a selection.

-- 
Cheers
macropod
[Microsoft MVP - Word]


"hassesetter" <hassesetter@discussions.microsoft.com> wrote in message news:E8BB54CD-866E-4842-ABDE-20FB99BCB268@microsoft.com...
>I have a template were the user should write what department he/she is 
> working on. The script works OK with Document_New but if the user is 
> miss-spelling or just want to change the name of the department (I do this 
> manually in testing mode by running the script again) there will be to 
> departments at the bookmark.
> I have tried to use a textfield but that disappear after using.
> Here is my code (were Enhet is Swedish for Department):
> 
> Option Explicit
> Dim Enhet As String
> Sub Document_New()
>    Enhet = InputBox("Vilken avdelning?")
>    ActiveDocument.Bookmarks("Enhet").Select
>    Selection.TypeText Enhet
> End Sub
> 
> Someone?
> 
> Hasse
0
macropod
11/13/2009 8:55:22 PM
Working perfect! Thanks a lot!
Hasse

"macropod" wrote:

> Hi hassesetter,
> 
> Try:
> Sub UpdateBookMark()
> Dim Enhet As String, BmkRng As Range
> Enhet = InputBox("Vilken avdelning?")
>  If ActiveDocument.Bookmarks.Exists("Enhet") Then
>   Set BmkRng = ActiveDocument.Bookmarks("Enhet").Range
>   BmkRng.Text = Enhet
>   ActiveDocument.Bookmarks.Add "Enhet", BmkRng
>  Else
>   MsgBox "Bookmark: Enhet not found."
>  End If
> Set BmkRng = Nothing
> End Sub
> 
> Note that there is no need for a selection.
> 
> -- 
> Cheers
> macropod
> [Microsoft MVP - Word]
> 
> 
> "hassesetter" <hassesetter@discussions.microsoft.com> wrote in message news:E8BB54CD-866E-4842-ABDE-20FB99BCB268@microsoft.com...
> >I have a template were the user should write what department he/she is 
> > working on. The script works OK with Document_New but if the user is 
> > miss-spelling or just want to change the name of the department (I do this 
> > manually in testing mode by running the script again) there will be to 
> > departments at the bookmark.
> > I have tried to use a textfield but that disappear after using.
> > Here is my code (were Enhet is Swedish for Department):
> > 
> > Option Explicit
> > Dim Enhet As String
> > Sub Document_New()
> >    Enhet = InputBox("Vilken avdelning?")
> >    ActiveDocument.Bookmarks("Enhet").Select
> >    Selection.TypeText Enhet
> > End Sub
> > 
> > Someone?
> > 
> > Hasse
> .
> 
0
Utf
11/16/2009 8:21:02 AM
Reply:

Similar Artilces:

Using iterations to calculate circular references.
I am working with data that requires using circular references in some calculations. I checked the "iterations" box to allow for these calculations to work, and Ecxel seems to be calculating everything correctly. The problem is that after I close the workbook, when I later reopen it to continue working, all the cells that are a part of the circular reference display the #VALUE! error. I can fix this by deleting one cell that is part of the loop and then undoing that command, or by copying the formula from a cell, deleting it, and pasting it back into the same cell. I have to d...

Microsoft CRM using Firefox
Hello, Would anyone by chance know if CRM will work correctly on Firefox. Currently, I have employees that are using Firefox and are encountering the same issue as IE [Internet Explorer bombs out and states that it has encountered problems...]. I am just having employees use IE to prevent problem. Thank you for your comments in advance. Install a Firefox extension called IETab "Marcos" <Marcos@discussions.microsoft.com> wrote in message news:19B93E29-757D-46FF-B747-A17EB112ED94@microsoft.com... > Hello, > > Would anyone by chance know if CRM will work cor...

excel, worksheet, set print area, position selection on printed pa
Office 07, Excel. Print area is set, print preview displays selection, always on far left of page. I want to choose the position on the page, eg centered or right aligned etc. Help please. Hi, To get your printout to center on the page chose Page Layout, click the Page Setup quick launch button (bottom right corner of the Page Setup group). Choose the Margins tab, click Horizontal. There is no command to right align a printout, but you can change the left margin to force the printout to the left. -- If this helps, please click the Yes button Cheers, Shane Devenshire "Eve Al...

preview text disappears when email is opened
When someone responds to an my email, I can see what they have typed - until I open the message - then only my original message is viewable. The preview pane shows new message text when email arrives, hoever when the email is opened the preview text disappears - and I just see the earlier part of the message which I had sent. If I mark it as unread it does not return to the previous state. This seems to happen on email responses that people have received and answered from a webmail service not that they downloaded and opened in outlook on their PC OL'03 XP pro sp2 -- Respectfully,...

Creating a template using Publisher
I need help creating a neighborhood directory template using Publisher and merging an Excel spreadsheet into it. It keeps printing multiple pages of the first page after I merge. What version Publisher? If you have 2003 use the catalog merge for your directory. http://office.microsoft.com/en-us/assistance/CH010504381033.aspx Otherwise you need to setup your page as though it is labels. Determine the size of the area you need for each entry, select labels in page setup, type the size you determined in the page setup. Adjust the gaps and margins when you are ready to print (2000 and bel...

How can I wrap text across merged cells?
I'm using Excel 2000. I have a set of merged cells A5- E5. I have several lines of text in the cells and I want them to wrap across the merged cells and it is not working. All I get is the first line of text showing and the rest is cut off. It works if the cells are not merged, but I really need to do it in my merged cells. Is there a way to this other than manually resizing the height of the row? Instead of merging cells, have you tried the "Center Across Selection" option ? The appearence is just about identical to what you would get using merged cells, although I d...

iPhone Email to Entourage Using Exchange
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel When I answer an email on my iPhone, it does not register it in Entourage as answered. This function worked fine until the business I work for put everyone on Exchange. Is there a setting for this that I can change? <br><br>Thanks! ...

Using Sumproduct when some of the values are null
I am having a problem using Sumproduct when some of the cells have null values. I will try to describe the problem. Please let me know if you need additional information. Do any of you have any ideas of how I can fix that sumproduct to get it to work? A B C Row Trend Claims 5 Emergency $0 6 Emergency $0 7 Emergency $0 8 Emergency 81.68% $24,444 9 Emergency 35.00% $164,758 10 Emergency 35.00% ...

Unable to repy using word editor
When repyling to an e-mail I receive the following message, "This form requires Word as your e-mail editor, but Word is either busy, or cannot be found. The form will be opened in the Outlook editor instead". I found article 284900, that states you may get this message when you have office 2000 and office xp installed on the same computer. This is not the case on my computer, Office 2000 does not exist, only office xp. Can anyone help me? There appear to be a whole host of causes for this error message. Most have no solution. Here are a few that do: http://support.microsoft...

Is anybody using Symantec Enterprise Vault?
Hi, A vendor has recommended this solution to us, I have looked at the datasheet for the product and it speaks the right language but I was wondering if anybody on here uses it in a live environment and what their opinion of it is. Cheers Sean ...

Operating a small passenger service
I am hoping someone has managed to customise outlook in a way that allows you to use the programe to manage bookings on a small passenger service. I.e input a new booking, number of people, location etc. Then email the days bookings to the different drivers. Maybe it could also be set up to know how many seats are avialale to reduce the risk of double booking? Im using Outlook 2003. ...

Unicode "private use" glyphs in Powerpoint and Word 2008 #2
Office 12.0.0.1 on Leopard 10.5.2, all updates applied to both. A friend is migrating from Windows to Mac, and has come across something that we're trying to work around. He has some .ppt files with font glyphs in from a Unicode .ttf font (a specific purpose font for showing the LCD display characters on a piece of monitoring equipment). When we bring the font and .ppt over to the Mac, the glyphs from the normal ASCII range come over into Powerpoint 2008 fine, but the glyphs from the "private use" range from F000 upwards a way don't transfer. In Powerpoint they show as spac...

using dates Part 2
Karl was great in helping me get to this point with dates, now I'm wondering if we can take it 1 step further? For Activity Dates prior to 2/1/2007 they are using a normal reporting year and the formulas below take care of Activity dates >2/1/2007? So for example prior to 2/1/2007 1/1/2006 would have a B_Qtr of 2006-1 1) B_Qtr - 2011-1 --- Format(DateAdd("m",11,[ActivityDate]), "yyyy - q") 2) Year - 2011 ---- Year(DateAdd("m",11,[ActivityDate])) 3) Qtr - Q1 ---- Format(DateAdd("m",11,[ActivityDate]), "q") -- Than...

what is straight line depreciation and double line depreciation?
See http://en.wikipedia.org/wiki/Depreciation In article <928DC52C-D390-45C6-9847-693648A1A5DA@microsoft.com>, MISSY <MISSY@discussions.microsoft.com> wrote: "JE McGimpsey" <jemcgimpsey@mvps.org> wrote in message news:jemcgimpsey-F62312.22355624092007@msnews.microsoft.com... > See > > http://en.wikipedia.org/wiki/Depreciation > Quite a good article for wikipedia, but it misses one very important point. The original purpose of charging depreciation to the P&L was to build up a reserve in order to replace the asset when it became obsol...

trouble using signature picker
The signature picker is ghosted out does anyone know how to correct this ? Signature picker was working earlier. Thanks ...

XP Look and Feel in Windows 2000 using ComCtrl32.dll
Hai I Want to have a XP Look and feel under windows2000 using VC++ and ComCtrl32.dll and does any one have any idea please help me as basically iam looking to develop a Skin Waiting for your reply suresh You will have to draw many of your own components. You could purchase a library like the one from www.codejock.com or www.dundas.com or or www.bcgsoft.com use something like this: These are for Office XP, but you'll get the idea. It's a ton of work: http://www.codeproject.com/miscctrl/officexp.asp Tom "suresh" <s...

Outlook 2007: is there a way to use it as a Diary
I'd like to keep a daily journal of important notes, etc. In other words , I would like to keep a Diary. Does Outlook 2007 have this capability? TIA Sure - Ctrl+8 to view the journal or you can create a Mail and Post folder type and post to it. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newsletter about Outlook and Exchange: mailto:EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH...

Find what control is using a data item
I built a form, then deleted 2 columns from the source table and now I get a popup asking for the value of those 2 columns. The problem is, I don't use those columns so I need to find what on the form is refferencing the deleted columns. I have looked at the control drop down on the properties window and the tab order window and can't find a control with either one of the missing column names. How do I determine what is trying to refference the deleted columns? I found the problem, the column was still referenced in the underlying query that fed the form. "MeSteve"...

VBA using an image as a toggle switch
Hi hope you can help. I know next to nothing about VBA and have adapted code below from stuff I had. I simply want to show hide portions of my page to cut down on screen clutter/information overload. I have assigned my macro to a screen image but was wondering if I could have a hide and unhide under the same button. Any help would be much appreciated Call Unl Application.ScreenUpdating = False Rows("25:75").EntireRow.Hidden = True Rows("98:148").EntireRow.Hidden = True Rows("171:221").EntireRow.Hidden = True Rows("244:294").EntireRow.Hidden = T...

Provide space in text
Where text and numbers are at different locations in different cells what formula could be used to suit this type of information. I want to be able to put a space between the main body of text on the left and give a space between the text and the start of any numbers are in the cell. Example 1: A1 = Abelia Edward Goucher2 litre Should be: Abelia Edward Goucher 2 litre Example 2: A2 = Acer campestre Nanum180stem 6-8 Should be: Acer campestre Nanum 180stem 6-8 Thankyou if can be of help. Pat If you double clcik in the cell with the data then you can move th blink line to were you wan...

Halfway through my publisher document the text starts scrambling
I am in the middle of a Publisher document that I have to get out ASAP and the words are scrmbling all of a sudden; for instance instead of the it prints out eht. HELP!! Might try an updated printer driver. What version Publisher are you using? What printer? What version Windows? Canon has issues with Publisher 98 and Windows 98 How to troubleshoot text printing (inkjet printers) in Publisher 2000 http://support.microsoft.com/default.aspx?scid=kb;en-us;198258&Product=pub PUB2000: Troubleshooting Text Printing (Laser Printers) http://support.microsoft.com/default.aspx?scid=kb;en-us;198...

Read file info using SMO locks database!
Hi! I'm using SMO from C# to restore a database from a backup file. Since I want to re-use the same datafiles I try to read the datafiles in my destination database and call RelocateFile to use these filenames during the restore. Everyting works fine except when I try to read the current datafilenames (see code below). If I skip this code and just hardcode the paths in relocatefile everything works fine. Database db = svr.Databases[destinationDBName]; foreach (FileGroup group in db.FileGroups) foreach (DataFile file in group.Files) Console.WriteLine...

OWA using mix of machine name/FQDN, screwing things up with HTTPS
Hello, We have one particular customer whose SBS 2003 box is giving me some heartburn when it comes to setting up OWA. I've set it up for HTTPS only, and setup permissions the exact same as our other many working OWA systems. Here's what happens when I try and hit the "broken" one: When I go to: https://server.domain.com/exchange, I get prompted for a username and password, which works properly. After login, I get a warning that the page contains a mix of both secure and non secure items. If I don't display the non secure items, I see the two "panes"...

GENERATE a TEXT FILE Using INPUT from a Form ??
I need to generate a Text file using (partly) information entered by the user on a form. I already have the TEMPLATE for the text file......I need to generate a COPY of the file with the word entered by the user into the form INSERTED into the text file. The text file is actually code for a web page (will have an .htm extension). The file is simply an exact copy of an existing template with only ONE ITEM of the text changed to a word that is entered into a form by a user. Example: One line within the template file is: "We have several of these items available in BLUE." I have...

Using a Tool to Modify Email Downloads (GGI)
Hello, If all possible, I would like to see Exchange pop email sooner than 15 minutes which appears to be the minimum it allows. Is there a Microsoft tool that allows to modify the download feature sooner than 15 minutes for email on the server? If yes, can someone please shed some light... Thank you in advance! POP is a email client access protocol. Exchange Server is not an email client. http://www.swinc.com/resources/exchange/smtp_diatribe.asp "George G. Ioannides" <gioannides@softhome.net> wrote in message news:%23iHAY2B3FHA.3868@TK2MSFTNGP12.phx.gbl... > &...