Wall switch has two black but no white wires we are replacing a cieling fan. The green or bare copper ground wire if the device has one attaches to the green screw terminal on the switch or to the electrical box.

How To Install A Light Switch Connecting A Light Switch To The Black Wires Part 1
Light switch both wires black. If all youve got is two black wires sticking out off the ceiling or wall then get your multimeter out and see if youve got 240v across the terminals or 110v if youre in usa etc. I cant believe nobodys said this already but if you have two wires and both of them are black and connected to the light switch then you dont have a neutral wire at all. The a wire wrapped around the screw can get thrown out with the switch. Make sure to shut off the power before doing this turn the breaker. With the power off connect the black hot wire to the old switch. Black means hot white signifies neutral and green indicates ground.
Cut the b wire off the gray switch and tie that to the black wire from the existing dimmer and the black wire off the new dimmer and youre golden. The white and bare wires are connected together and the bare wire is also connected to the green screw on the switch body. Its essential that you determine which black wire is hot before proceeding. This wire is sometimes red. The switch may have gold and silver colored screws. The neutral white wires should be pig tailed together in the box.
If so connect the input hot lead to the gold and the lamp hot lead to the silver. The black wire hot is switched so both black wires are connected to the switch. There is also a green screw on the side and this is for the ground. Florida reporting in id like to introduce you to the abomination of sense that we call phase tape. Turn the power back on and turn the switch on. The black hot wire goes to the brass screw or into the hole in the back of the device on the same side as the brass screw.
The black wires are labeled and indicate that they are not to be connected to white wires. If thats not obvious to you then dont touch it and get a com. The new cieling fan has its own wall switch and the new wall switch has two black and one green wires. One of the two non hot black wires is the light feed and the other is a feed to other loads possibly some receptacles but it doesnt matter. You connect the black wires in the electrical box to the switch terminals and the white wires to each other. As the first post says.
However if you need to rewire a light switch or a plug socket you may occasionally come across two black wires. The current switch is set up as having a hot wire in from the breaker box to the switch and a hot wire out from the switch to the light. The other black wire on your gray switch switch will get thrown away with the switch. Hooking up a switch is the essence of simplicity. The switch also has a green terminal. Connect either of the other two black wires to the other screw on the switch.
The easiest and safest way is to use a multimeter to test for current.