macro not running until worksheet is clicked

norwester

New Member
Joined
Jul 17, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am using a macro that checks if an image file has been added to a folder.
The image file comes from a camera that is operated by canon remote shooting software on the same pc.
When I use the remote shooting software to take a photo, the macro calls a second macro that asks to rename the file using an input box.
However that input box does not appear until I click anywhere on the worsheet. If I operate the camera manually then the 2nd macro works fine
but that rather defeats the purpose of operating the camera by the computer.
It seems that by clicking outside of the excel window to operate the camera somehow the second macro is called but does nothing until I click on the excel workbook

this is the first macro
Sub check_files()
'this macro runs in a loop until an image is downloaded to folder temp_canon_images
'when that happens the macro get name is run
temp_image = ""

Do
msg = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set fils = fso.GetFolder("C:\superkids_digital\temp_canon_images").Files

For Each fil In fils
temp_image = fil.Path 'temp_image contains the file path and file name
Next fil

Loop Until temp_image <> ""
Call get_name
End Sub

this is the second macro
Sub get_name()
Application.ScreenUpdating = True
Workbooks(1).Activate
Cells(4, 8).Select
MsgBox "new photo has ben downoaded"

first_name = InputBox("Enter first name", , "Joe")
surname = InputBox("Enter surname", , "Bloggs")
full_name = first_name + " " + surname

Application.Wait (Now + TimeValue("0:00:5")) 'wait 5 seconds to allow file to be completley downloaded
'this code has to run again because the initial file name is different to the final file name after it is downoaded
Set fso = CreateObject("Scripting.FileSystemObject")
Set fils = fso.GetFolder("C:\superkids_digital\temp_canon_images").Files
For Each fil In fils
temp_image = fil.Path 'temp_image contains the file path and file name
Next fil

old_file = temp_image
new_file = "C:\superkids_digital\named_images\" + full_name + ".jpg"

Name old_file As new_file 'file is renamed and moved to the named images folder
Set fso = Nothing
Stop
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi and welcome to MrExcel

Not tested
In the macro "check_files" after this line
temp_image = ""

add this line:
DoEvents
 
Upvote 0
I have tried putting doevents in various places but makes no difference tks
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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