The invention relates to a method (100) for ascertaining a focused image distance of an optical sensor (14) of a coordinate measuring device (10) to a workpiece (12) to be measured. The optical sensor (14) and the workpiece (12) can be moved relative to each other in a Z direction (20) such that a distance (22) in the Z direction (20) between the workpiece (12) and the optical sensor (14) can be changed. The method has the following steps: determining (102) a capturing region (38) between a first distance, as the starting distance (34), and a second distance, as the end distance (36); carrying out a first change of the distance (22) between the workpiece (12) and the optical sensor (14) within the capturing region (38), wherein the optical sensor (14) detects first images of the workpiece (12) while the distance (22) is changed, and a first focus value (52) and a first image distance are assigned to each detected first image; analyzing (106) the first focus values, determining a preliminary focused image dist