Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
Old August 16th, 2009, 10:25 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
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)
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
Old August 17th, 2009, 09:01 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
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)
Reply With Quote
  #5 (permalink)  
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
Reply With Quote
  #6 (permalink)  
Old August 18th, 2009, 07:49 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
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)
Reply With Quote
  #7 (permalink)  
Old August 24th, 2009, 01:42 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
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)
Reply With Quote
The Following User Says Thank You to Shasur For This Useful Post:
IranianCuriousBoy (September 5th, 2009)
  #8 (permalink)  
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.
Reply With Quote
  #9 (permalink)  
Old September 5th, 2009, 10:47 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.