Can I control the position of a filedialog window?

JohnWLee

New Member
Joined
Aug 23, 2010
Messages
12
We have recently changed to dual monitors and annoyingly when the Excel application is expanded across both screens, any filedialog window that is invoked by a macro sits right in the middle of the split.

I can control the position of userforms with the .Top and .Left form properties but don't know know how to, or even whether I can, control the position of a filedialog.

Any tips gratefully received.

Thanks in anticipation.

John
 
Hello

Thank you very much, this is just what I have been looking for and have not been able to find or do.

May I ask you a few questions about the code

In the declaration "Private Const NULL_PTR = 0&" is the "&" used as a Type Declaration Character to force the NULL_PTR const to be a long?

In the declaration "Private Const NULL_PTR = 0^" what is the "^" for? I can't find ^ used as a Type Declaration Character in on the Microsoft VBA web site.

What does the following code do
Private Enum LongPtr
[_]
End Enum

Given that Option Base is not specified in the programme header (and is therefore 0) and only elements 0 & 1 of array Pos are used why is it necessary to specify it as Pos(2&)

Given that "Dim Pos(2&) As Long" specified Pos as an array of longs, why is it necessary to specify the array index as Long by using &?

Once again thank you for the code and I hope you can find time to answer the questions above, as it will help me to understand your code.

Best Regards

Charles
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi CharlesRattletail

In the declaration "Private Const NULL_PTR = 0&" is the "&" used as a Type Declaration Character to force the NULL_PTR const to be a long?
In the declaration "Private Const NULL_PTR = 0^" what is the "^" for? I can't find ^ used as a Type Declaration Character in on the Microsoft VBA web site.
Const NULL_PTR = 0^ is there to force the const to be a 8bit LongLong. I consider this to be good practice particularly when working with the win32 api.

Some api functions expect\return LongLong values.

As an example, the SetWindowPos api expects a HWND in its second (hWndInsertAfter) argument... The C\C++ HWND data type translates into an 8bit LongLong in x64bit excel.

Although in this case, passing just 0 or 0& will still work and will evaluate to LongLong in x64bit excel, I prefer to use the correct data type NULL_PTR for consistency and cleaner code.

What does the following code do
Private Enum LongPtr
[_]
End Enum

In VBA5/VBA6 ( Excel 2007 or ealier) , the LongPtr *data type* doesn't exist. Therefore, if the code happens to be running in VBA5/VBA6 , LongPtr will not compile... But since we are defining LongPtr as an Enum, it will be a valid type, evaluating to Long since Enums are internally defined by VB as Long.

Now, the reason for doing this is to save you the hassle to use conditional compilation repeatedly througouht the code each time LongPtr is encountered... So, using this Enum trick will substantially reduce the number of conditional compilations needed in the code particularly if the code is large and there are many instances of LongPtr. This will also reduce the chances of making data type mistakes ( 4bit Long vs 8bit LongPtr in excel x64bit)

BTW, it is worth remembering that LongPtr is not in fact a true data type. it translates into either Long or LongLong depending on the process bitness.

Given that Option Base is not specified in the programme header (and is therefore 0) and only elements 0 & 1 of array Pos are used why is it necessary to specify it as Pos(2&)
Yes. That was my mistake. It should have been Dim Pos(1&) As Long ... Lucky it worked here.

Given that "Dim Pos(2&) As Long" specified Pos as an array of longs, why is it necessary to specify the array index as Long by using &?
Adding the & type declaration character is just a habit I got into to coerce litteral numbers into Longs . In this case, using Pos(2) or Pos(2&) won't make any difference as array indexes are of signed 32bit longs ... Note that we are talking here about data type of array indexes not about data type of array data (content) which can be of any type.
 
Last edited:
Upvote 0
Hi CharlesRattletail


Const NULL_PTR = 0^ is there to force the const to be a 8bit LongLong. I consider this to be good practice particularly when working with the win32 api.

Some api functions expect\return LongLong values.

As an example, the SetWindowPos api expects a HWND in its second (hWndInsertAfter) argument... The C\C++ HWND data type translates into an 8bit LongLong in x64bit excel.

Although in this case, passing just 0 or 0& will still work and will evaluate to LongLong in x64bit excel, I prefer to use the correct data type NULL_PTR for consistency and cleaner code.



In VBA5/VBA6 ( Excel 2007 or ealier) , the LongPtr *data type* doesn't exist. Therefore, if the code happens to be running in VBA5/VBA6 , LongPtr will not compile... But since we are defining LongPtr as an Enum, it will be a valid type, evaluating to Long since Enums are internally defined by VB as Long.

Now, the reason for doing this is to save you the hassle to use conditional compilation repeatedly througouht the code each time LongPtr is encountered... So, using this Enum trick will substantially reduce the number of conditional compilations needed in the code particularly if the code is large and there are many instances of LongPtr. This will also reduce the chances of making data type mistakes ( 4bit Long vs 8bit LongPtr in excel x64bit)

BTW, it is worth remembering that LongPtr is not in fact a true data type. it translates into either Long or LongLong depending on the process bitness.


Yes. That was my mistake. It should have been Dim Pos(1&) As Long ... Lucky it worked here.


Adding the & type declaration character is just a habit I got into to coerce litteral numbers into Longs . In this case, using Pos(2) or Pos(2&) won't make any difference as array indexes are of signed 32bit longs ... Note that we are talking here about data type of array indexes not about data type of array data (content) which can be of any type.
Thank you or the reply, know i understand.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top