Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 15th, 2009, 10:42 PM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Detemine which part is double clicked

Hi
I am using WindowBeforeDoubleClick event and want to know which part of a document is clicked. The StoryType of Sel(The Selection object) always have the value of 1 so it is impossible to specify which part is double clicked. I provided the main problem that I want to solve in case you want to know it.
What I want to do:
when header and footer is double clicked, a form apears whithout activating header and footer for editing and also the document is not scrolled.
Thanks
 
Old August 16th, 2009, 10:25 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Can you try this following:

Code:
Sub WhereISelected()

If Selection.Information(wdInHeaderFooter) Then
 MsgBox "Within Header"
End If

End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old August 16th, 2009, 10:48 PM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default It still doesn't work

The code is:
Code:
Option Explicit
'reserve memory for an application variable
Private WithEvents wdApp As Word.Application

Private Sub Document_Open()
'assign Word to the application variable
If wdApp Is Nothing Then
    Set wdApp = ThisDocument.Application
End If
End Sub

Private Sub wdApp_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
     MsgBox Sel.Information(wdInHeaderFooter)
     Cancel = True
     DocumentInfo.Show
End Sub
I added the message box to show the value of Information(wdInHeaderFooter) for Sel. The value is always false no matter which part is double clicked.
It seems the Sel object has no information about which part is double clicked but another question is, why it is in the signiture of this event?

Thanks
 
Old August 17th, 2009, 09:01 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Your event works fine in my machine - Windows XP - Word 2003.

Can you give the version where it fails

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old August 18th, 2009, 03:16 AM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi
I have the same condition(Windows XP - Word 2003) and I suspected the file I was working on. So I created a new file and pasted the code into it(except DocumentInfo.Show). The problem still exists!
Tell me how can I send you this file for you?
Thanks
 
Old August 18th, 2009, 07:49 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you send the file to shasur9771 at rediffmail dot com

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old August 24th, 2009, 01:42 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Got your document

Even if you are 'clicking' the Header actually the cursor is in the body text only.

Can you try clicking the header text using 'Edit --> Header' option

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
The Following User Says Thank You to Shasur For This Useful Post:
IranianCuriousBoy (September 5th, 2009)
 
Old September 5th, 2009, 07:15 AM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Thanks

Hi
sorry for being late.
It seems there is a problem with WindowBeforeDoubleClick. It shows where the cursor is not where double clicked!
I used WindowSelectionChange instead. it has some disadvantages like activating header/footer and also when header/footer is deactivated by code, scrolls the document the the place where the cursor is.
anyway thanks.
 
Old September 5th, 2009, 10:47 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Glad that it was solved
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
which row is clicked in gridwiew vipsis ASP.NET 2.0 Basics 1 March 13th, 2007 07:22 AM
How to replace a picture with another when clicked BLaZuRE Beginning VB 6 2 March 11th, 2006 04:08 PM
How to know whick button was clicked. KingArthur Struts 1 February 22nd, 2006 07:12 AM
close the frame this is in when clicked crmpicco HTML Code Clinic 2 August 31st, 2005 08:23 AM
How to tell which button clicked emily PHP How-To 2 November 30th, 2004 01:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.