7 Replies - 3954 Views - Last Post: 05 February 2011 - 04:36 AM Rate Topic: -----

#1 N62790  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-January 11

VBA active file handle in excel macro

Posted 30 January 2011 - 02:55 AM

Is it possible to read the active file handle in an excel macro and write data directly to that open file?
Is This A Good Question/Topic? 0
  • +

Replies To: VBA active file handle in excel macro

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: VBA active file handle in excel macro

Posted 30 January 2011 - 04:55 AM

Yes, that are macros for.
Was This Post Helpful? 0
  • +
  • -

#3 N62790  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-January 11

Re: VBA active file handle in excel macro

Posted 30 January 2011 - 05:37 AM

View PostIonut, on 30 January 2011 - 04:55 AM, said:

Yes, that are macros for.

Hi IOnut, sorry maybe I have to express myself a little better:
An excel file i.e. 'a.xls' is open and from this excel file the macro editor is opened. Now I try to find out how I can access the excel file itself, that means I would like to identify the file handle and then use this handle to read or write data to the binary code of this excel file (not to the excel table).
Was This Post Helpful? 0
  • +
  • -

#4 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: VBA active file handle in excel macro

Posted 31 January 2011 - 08:50 AM

what do you mean? write the file in binary's then how excel open that file?
i think may be i am wrong? make it clear do you want overwrite the cell value(like a mask)
Was This Post Helpful? 1
  • +
  • -

#5 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: VBA active file handle in excel macro

Posted 01 February 2011 - 03:29 AM

If I undestand correct, you want an "old style" manipulation of an xls file, like a binary open in C/C++. This I think can be achived only with WinApi functions. VBA had the purpose to make easier excel files manipulation in a "high level" way: working directly with cell, worksheets, ranges through objects.

Quote

An excel file i.e. 'a.xls' is open and from this excel file the macro editor is opened. Now I try to find out how I can access the excel file itself,

If an excel file is open, you cannot write data the way you want. It should get the path, close it and then open the file through winapi.
Was This Post Helpful? 2
  • +
  • -

#6 N62790  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-January 11

Re: VBA active file handle in excel macro

Posted 03 February 2011 - 06:50 AM

View PostIonut, on 01 February 2011 - 03:29 AM, said:

If I undestand correct, you want an "old style" manipulation of an xls file, like a binary open in C/C++. This I think can be achived only with WinApi functions. VBA had the purpose to make easier excel files manipulation in a "high level" way: working directly with cell, worksheets, ranges through objects.

Quote

An excel file i.e. 'a.xls' is open and from this excel file the macro editor is opened. Now I try to find out how I can access the excel file itself,

If an excel file is open, you cannot write data the way you want. It should get the path, close it and then open the file through winapi.

Hi IOnut, you are right with your description. I definitely have to change my approach. Thank you very much for your help and time spend.

View Postthava, on 31 January 2011 - 08:50 AM, said:

what do you mean? write the file in binary's then how excel open that file?
i think may be i am wrong? make it clear do you want overwrite the cell value(like a mask)

Hi Thava, you are right I did want to write binary to the file and not just change a field or cell. I will look for an other solution. In any case thank you for your contribution. take care.
Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: VBA active file handle in excel macro

Posted 04 February 2011 - 02:17 PM

Ionut is quite right. Read up on the EnumWindows API function: http://msdn.microsof...(v=vs.85).aspx.

Here's the VB translation of the function specification (use the "Windows API Viewer" in VS 6.0 Tools menu folder to find these):
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long



The way this works is you create a Sub, pass the name of the sub to lpEnumFunc using the AddressOf operator, and this function will go through all the top level windows on the screen and call your sub once for each window, passing each handle in as it goes.

HTH
Was This Post Helpful? 1
  • +
  • -

#8 N62790  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-January 11

Re: VBA active file handle in excel macro

Posted 05 February 2011 - 04:36 AM

View PostBobRodes, on 04 February 2011 - 02:17 PM, said:

Ionut is quite right. Read up on the EnumWindows API function: http://msdn.microsof...(v=vs.85).aspx.

Here's the VB translation of the function specification (use the "Windows API Viewer" in VS 6.0 Tools menu folder to find these):
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long



The way this works is you create a Sub, pass the name of the sub to lpEnumFunc using the AddressOf operator, and this function will go through all the top level windows on the screen and call your sub once for each window, passing each handle in as it goes.

HTH



Hi Bob,
thanks for your hint, I will try to follow your link ... :-)
might be helpfull for other applications as well ...
blue skies
Gunther Spitzer
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1